1
我使用jQuery AJAX得到一个XML文件:XML保存所有的孩子可变
$.ajax({
type: "GET",
url: phoneXmlPath,
dataType: "xml",
contentType: "text/xml; charset=utf-8",
success: function(xml){
$(xml).find("phone[phone_id="+phone_id+"]").each(function(index, value){
var tis = $(this);
tis.children().each(function(){
alert($(this).nodeName);
});
});
},
error:function(xhr,type){
if(type == null){
var errorMsg = "There was an error loading the phone.xml file!<br/>Please make sure the path to the xml file <strong>'"+phoneXmlPath+"'</strong> is correct.";
}else if(type == "parsererror"){
var errorMsg = "There is an error in the file <strong>'"+phoneXmlPath+"'</strong>.";
}else{
var errorMsg = "An error has been detected.";
}
popup.removeClass("loading").html("<p><strong>Error:</strong> "+errorMsg+"</p><p><strong>Type of error:</strong> "+type+".</p>");
}
});
在这一部分:alert($(this).nodeName);
我怎么能保存所有的变量,我以后可以访问。例如,我希望能够做到的代码:“phone.title”,并访问所有电话儿童元素。
XML文件
<phones>
<phone>
<phone_id>123</phone_id>
<title>Phone title</title>
etc....
+1救救孩子! ;-) – mAndroid