[英]I can not load data on AJAX
我有一个旧脚本正在从xml文件加载IP。 半年前,该脚本一切正常。 现在我想再次使用它,它不起作用。 我不知道发生了什么 浏览器或...有什么改变吗? 这是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");
}
});
和XML称为config3.xml
<config><ip>192.168.0.102</ip></config>
它根本不起作用。 没啥事儿。 没有错误。 没什么。 请帮忙
问题可能在于您的对象的格式不正确。
删除var host;
的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>
尝试这个:
$.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.