【发布时间】:2012-04-03 22:43:06
【问题描述】:
我已经尝试了几种方法让我的 xml 脚本在 java 中解析,但我无法弄清楚!
我有 2 个文件。 如果调用 mysql_get.php,它会返回一个 XML 脚本。 post_alert.html 通过 jQuery $.post(..) 从 mysql_get.php 获取 XML 脚本,如下所示:
function init2() {
var response;
$.post("mysql_get.php", function (data) {
response = data;
alert(response)
});
var xml;
xml = $.parseXML(response);
alert($(response).find("item").each(function () {
$(this).attr("id")
}));
}
点击一个调用 init2() 的按钮后,我得到了 xml 样式的响应消息,正如我在弹出的警报中看到的那样。
<?xml version="1.0" encoding="uft-8"?>
<root>
<collection collection="locationPoint">
<item id="1">
<latitude>23.4442</latitude>
<longitude>51.2341</longitude>
</item>
<item id="2">
<latitude>2849.24</latitude>
<longitude>213.132</longitude>
</item>
</collection>
但是警报没有弹出“1”,因为我希望正确解析。
我做错了什么?
【问题讨论】:
标签: javascript jquery xml ajax parsing