开发者

Problem with xml parsing in phonegap application [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 9 years ago.

Improve this question

I want to parse xml webservice in my phonegap application but i don't have any idea how is it possiblem.I tried it with my local xml file which is st开发者_运维百科ored in my remote server and it is working fine but when i am calling server side xml file then i am not getting any result.Pls anybody have idea then please solve my issue. Pls any one have working simple code then pls send it to me. I tried to find out my solution from google but didn't get any answer .Please solve my issue.My server file is http://www.edumobile.org/blog/uploads/XML-parsing-data/Data.xml.


please try following code in your index.html file, I have tested the url (http://www.edumobile.org/blog/uploads/XML-parsing-data/Data.xml) in iPhone/Android Simulator and its work like 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'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:'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-

Problem with xml parsing in phonegap application [closed]


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>

Button to call the above method:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜