Load and parse a XML through an URL un Jquery
<script src="jquery-1.5.2.min.js" type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "GET",
url: "http://rama.inescporto.pt/app/api/",
data: "method=getGraph&artist=Coldplay&ri=3&p=3&d=0.5",
dataType: "xml",
success: xmlParser
});
});
function xmlParser(开发者_Go百科xml) {
$('#load').fadeOut();
$(xml).find('element').each(function(){
$(".main").append('<div class="artist"><p class="id">' + $(this).find('id').text() + '</p><p class="name">' + $(this).find("name").text() + '</p><p class="rank">Published ' + $(this).find("rank").text() + '</p></div>');
$(".artist").fadeIn(1000);
});
}
</script>
</head>
<body>
<div class="main">
<div align="center" class="loader"><img src="images/loading-spiral.gif" id="load" align="absmiddle"/></div>
</div>
I think I have all correct, but the request does not happen, the success function does not kick in. Someone can see where did I get it wrong?
You cannot use AJAX to send a request to a different domain.
Due to SOP browser rejects that request. You can use AJAX only on the same host (ip address and port), and the same protocol the original page is open from.
Edit:
If your page is here: http://rama.inescporto.pt/
make sure that you are writing a correct relative path to the page you want to get through AJAX: /app/api
.
Also, try to open http://rama.inescporto.pt/app/api/
in a browser. Do you get XML then?
精彩评论