2012-09-28 3 views
0

Dans le code ci-dessous je tente de lire les détails du livre forment une URL, mais il ne montre pas l'écran de sortie output.In en cliquant sur le bouton ajax, il ne sera pas entrer dans la $(data).find("Book").each(function(){});webservice fonction jquery

Mon code html:

<html> 
<head> 
<script src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.js" type="text/javascript" charset="utf-8"></script> 
<script src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js" type="text/javascript"></script> 
<script type="text/javascript"> 
function bodyload() { 
    alert("We are calling jquery's ajax function and on success callback xml parsing are done"); 
    $.ajax({ 
     url: 'http://www.edumobile.org/blog/uploads/XML-parsing-data/Data.xml', 
     dataType: 'application/xml', 
     timeout: 10000, 
     type: 'GET', 
     success: function(data) { 
      alert("inside success function"); 
      $("#bookInFo").html(""); 
      $("#bookInFo").append("<hr>"); * * // my code work until here after that i will not receive any book details in my web page.** 
      $(data).find("Book").each(function() { 
       $("#bookInFo").append("<br> Name: " + $(this).find("name").text()); 
       $("#bookInFo").append("<br> Address: " + $(this).find("address").text()); 
       $("#bookInFo").append("<br> Country: " + $(this).find("country").text()); 
       $("#bookInFo").append("<br><hr>"); 
      }); 
     }, 
     error: function(XMLHttpRequest, textStatus, errorThrown) { 
      alert("Error status :" + textStatus); 
      alert("Error type :" + errorThrown); 
      alert("Error message :" + XMLHttpRequest.responseXML); 
      $("#bookInFo").append(XMLHttpRequest.responseXML); 
     } 
    }); 
}​ 
</script> 
</head> 
<body> 
<center><button onclick="bodyload()">Ajax call</button></center> 
<p id="bookInFo"></p> 
</body> 
</html> 

S'il vous plaît me dire pourquoi je ne reçois pas de sortie.

while running the the code in ios simulator i ll gett this alert msg only

if i run the file in chrome i will get this output but not returns the web service output

+0

Avez-vous débogué? Que montre 'console.log (data);' show? – epascarello

+1

Vous devez supprimer l'une de ces références à 'jquery.js', vous en avez seulement besoin. –

Répondre

0

Je pense que le paramètre de données de la fonction de réussite est un objet de js analysé xml, pas le html \ dom. Vous ne pouvez pas lui appliquer $(). Essayez d'

for(var i = 0; i < data.length; i++) {var name = data[i].name; etc...} 

ou

for(var prop in data){var name = data[prop].name; etc...}