用jquery解析xml

首先,如果是动态生成的xml,必须设置Content-Type为”text/xml”,否则默认的就是文本了。
其次,生成的xml必须为封闭的。即格式一定要正确。
这样,就可以解析了xml,例:

?View Code JAVASCRIPT$.ajax({
url:’ajax.asp’,
type: ‘GET’,
dataType: ‘xml’,//这里可以不写,但千万别写text或者html!!!
timeout: 1000,
error: function(xml){
alert(’Error loading XML document’+xml);
},
success: function(xml){
$(xml).find("student").each(function(i){
[...]

Also tagged ,