因此,我编写了一些JavaScript来从我的桌面抓取xml文件并将其显示在html页面上。但是,我现在已经将我的xml文件添加到web服务器(mongoose)。我想从该服务器调用该文件,但每当我从服务器调用该文件时都不起作用,但是当我从桌面调用该文件时,它会正常加载。使用Javascript从服务器获取文件

我想交换

xmlhttp.open("GET","Devices.xml",false);

xmlhttp.open("GET","http://localhost:8080/Devices.xml",false);

下面是代码

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 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 "

name: " + name + "
uuid: " + uuid + "
id: "+ id + "

";

}

// 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;

};

有谁知道我能得到这个工作?

我被告知使用AJAX和JQuery,但我不知道如何甚至从何处开始。

2011-07-12

Matt

+6

您是否正在服务从同一个Web服务器获取该文件的页面?如果不是,你可能会遇到一些相同的原产地问题 –

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐