我有一个XML文件和HTML下htdocs的我已经在我的机器本地设置的Apache。无法使用jQuery读取XML文件
我试图读取XML文件,但我没有得到任何回应。它甚至没有提醒状态。另外,如果我给无效的文件名称,它没有显示任何区别。该xml文件是有效的。谁能告诉我我在哪里失踪。
<script>
$(document).ready(function(){
console.log('hey');
$.ajax({
type: "GET",
url: "feedTest.xml",
cache: false,
dataType: "xml",
success: function(xml){
alert(status);
}
});
$("#output").append("Some Text");
});
function parseXML(xml){
$(xml).find("mainPage").each(function(){
console.log("I'm in");
$("#output").append($(this).attr("time") + "<br/>");
});
}
</script>
<body>
<div id="output">
Hello
</div>
XML文件:
<?xml version="1.0"?>
<!--
Comments
-->
<dashboard>
<mainPage time="20">
<horizontal>2</horizontal>
<vertical>3</vertical>
<loop set="true"></loop>
<files>
<name time="10">a</name>
<name time="10">b</name>
</files>
</mainPage>
</dashboard>
你有没有尝试添加错误处理程序到你的$就要求用警惕看什么回来? – dSquared
@dSquared感谢您的想法。我试过了,得到这个:[Exception ...“”nsresult:“0x805e0006()”location:“JS frame :: http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery .min.js :: .send :: line 6“data:no] –
Crocode
听起来像是一个跨域问题,是与脚本调用它在同一个域的同一个端口上的XML文件吗? – dSquared