使用jQuery从URL解析XML
问题描述:
我想从此XML(http://stagservices.upol.cz/ws/services/rest/student/getStudentInfo?osCislo=R140742)中取回“jmeno”,并且每次都返回错误。使用jQuery从URL解析XML
$(document).ready(function() {
$.ajax({
type: 'GET',
url: 'http://stagservices.upol.cz/ws/services/rest/student/getStudentInfo?osCislo=R140742',
crossDomain: true,
dataType: "jsonp",
success: parseXml,
error: function() {
alert("Error: Something went wrong");
}
});
});
function parseXml(xml) {
$(xml).find('student').each(function() {
$("#output").append($(this).find('jmeno').text() + "<br />");
});
}
答
使用datatype: 'xml'
。
$(document).ready(function() {
$.ajax({
type: 'GET',
url: 'http://stagservices.upol.cz/ws/services/rest/student/getStudentInfo?osCislo=R140742',
crossDomain: true,
dataType: "xml",
success: function(data){
console.log(data);
},
error: function() {
alert("Error: Something went wrong");
}
});
});
的Tru使用'.parseXML()'https://api.jquery.com/jQuery.parseXML/ –
什么happend – user3407775
可能是错误的跨域网络安全构成了浏览器 – Kirween