[英]I can not load data on AJAX
I have an old script which is loading IP from xml file. 我有一个旧脚本正在从xml文件加载IP。 Everything was working fine half year ago on that script.
半年前,该脚本一切正常。 Now i wanted to use that again and it is not working.
现在我想再次使用它,它不起作用。 I don't know what happened.
我不知道发生了什么 Is there something changed on browser or... ?
浏览器或...有什么改变吗? Here is the Javascript
这是Javascript
$.ajax({
var host;
type: "GET",
url: "config/config3.xml",
async : false,
dataType: "xml",
success: function(xml) {
$(xml).find('config').each(function () {
host = $(this).find('ip').text();
alert(host);
});
},
error: function(xml) {
alert("No XML file");
}
});
And XML called config3.xml 和XML称为config3.xml
<config><ip>192.168.0.102</ip></config>
It is not working at all. 它根本不起作用。 Nothing happened.
没啥事儿。 No errors.
没有错误。 Just nothing.
没什么。 Please help
请帮忙
The problem might lie in the fact that you have an improperly formed object. 问题可能在于您的对象的格式不正确。
Remove var host;
删除
var host;
HTML 的HTML
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script>
$.ajax({
type: "GET",
url: "config/config3.xml",
async : false,
dataType: "xml",
success: function(xml) {
console.log('xml success', xml);
var host;
$(xml).find('config').each(function () {
host = $(this).find('ip').text();
alert(host);
});
},
error: function(xml) {
alert("No XML file");
}
});
</script>
try this: 尝试这个:
$.ajax({ type: "GET", url: "config/config3.xml", async : false, dataType: "xml", success: function(xml) { var xmlDoc = $.parseXML(xml) xmlDoc.find('config').each(function () { host = $(this).find('ip').text(); alert(host); }); }, error: function(xml) { alert("No XML file"); } });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.