使用URL中的jQuery解析XML

时间:2015-09-04 12:01:20

标签: jquery xml

我想从这个XML(http://stagservices.upol.cz/ws/services/rest/student/getStudentInfo?osCislo=R140742)取回“jmeno”,每次都会收到错误。

$(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 />");
    });
}

1 个答案:

答案 0 :(得分:0)

<强> DEMO

使用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");
          }
      });
  });