2015-09-04 86 views
0

我想從此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 />"); 
    }); 
} 
+0

的Tru使用'.parseXML()'https://api.jquery.com/jQuery.parseXML/ –

+0

什麼happend – user3407775

+0

可能是錯誤的跨域網絡安全構成了瀏覽器 – Kirween

回答

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