私は、デスクトップからxmlファイルを取得し、htmlページに表示するためのJavaScriptをいくつか書きました。しかし、私は今xmlファイルをWebサーバー(mongoose)に追加しました。私はそのサーバーからファイルを呼び出したいと思うが、サーバーからファイルを呼び出すときはいつでもうまくいきませんが、デスクトップから呼び出すとうまく読み込みます。私はここでJavascriptを使用してサーバーからファイルを取得する
xmlhttp.open("GET","http://localhost:8080/Devices.xml",false);
で
xmlhttp.open("GET","Devices.xml",false);
を交換したい
はコード
<html>
<head>
<script type="text/javascript">
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","Devices.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
// the <Device> list
x = xmlDoc.getElementsByTagName('Device');
// make a function that extracts the attributes out of a Node
function getDeviceAttributes(dvc) {
var name = dvc.getAttribute("name");
var uuid = dvc.getAttribute("uuid");
var id = dvc.getAttribute("id");
return "<p>name: " + name + "<br> uuid: " + uuid + "<br> id: "+ id + "</p>";
}
// loop through the list
// assuming order doesn’t matter
var txt = '';
for (var i = x.length; i--;) {
txt += getDeviceAttributes(x[i]);
}
//show the result on page load
window.onload = function() {
document.getElementById("showDevices").innerHTML = txt;
};
</script>
</head>
<body>
<div id='showDevices'></div>
</body>
</html>
私はこの作業を取得することができますどのように誰もが知っていますか?
私はAJAXとJqueryを使用するように言われていますが、どうやってどこから始めるべきか分かりません。
あなたは、同じWebサーバーからそのファイルを取得するページを提供していますか?同じ起源の問題に遭遇している可能性があります –