Problem with xml parsing in phonegap application

I want to parse the xml webservice in a phone conversation application, but I don't know how this is possible. I tried it with my local xml file, which is stored on my remote server, and it works fine, but when I call the server side XML file, then I get no result. Anyone have an idea, then please solve my problem. Pls anyone have worked a solid code then pls send it to me. I tried to figure out my solution from Google, but did not receive a response. Please resolve my problem. My server file is http://www.edumobile.org/blog/uploads/XML-parsing-data/Data.xml .

+4
source share
2 answers

try entering the code in the index.html file, I checked the URL ( http://www.edumobile.org/blog/uploads/XML-parsing-data/Data.xml ) in iPhone / Android Simulator and it works like a charm.

<html> <head> <script src="js/jquery-1.4.2.js" type="text/javascript" charset="utf-8"></script> <script src="js/jquery-1.4.2.min.js" type="text/javascript"></script> <script> function bodyload(){ alert("We are calling jquery 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:'POST', success:function(data) { $("#bookInFo").html(""); $("#bookInFo").append("<hr>"); $(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 onload="bodyload()"> <button onclick="bodyload()">Ajax call</button> <p id="bookInFo"></p> </body> </html> 

output- enter image description here

+2
source

Use this:

 <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.css" /> <script src="http://code.jquery.com/jquery-1.4.4.min.js"></script> <script src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.js"></script> <script type="text/javascript"> $(function() { $("#requestXML").click(function() { $.ajax({ type: "POST", url: "http://www.edumobile.org/blog/uploads/XML-parsing-data/Data.xml", data: "{}", cache: false, dataType: "xml", success: onSuccess }); }); $("#resultLog").ajaxError(function(event, request, settings, exception) { $("#resultLog").html("Error Calling: " + settings.url + "<br />HTTP Code: " + request.status); }); function onSuccess(data) { $("#resultLog").append(""+data); $(data).find("Book").each(function () { $("#resultLog").append("<br> Name: " + $(this).attr("name")); $("#resultLog").append("<br> Address: " + $(this).attr("address")); $("#resultLog").append("<br> Country: " + $(this).attr("country")); $("#resultLog").append("<br><hr>"); }); } }); </script> 

Call button of the above method:

 <input id="requestXML" type="button" value="Request XML" /> 
0
source

All Articles