I want to access open API through ajax in mobile application, its work fine in iphone but does not working in Android phonegap application:
returning error->"error message-null,typeerror-Result of expression 'data'[null] is not an object and error status-parsererror"
Is there any browser setting need to follow.
I want to call the web service in android-phonegap application:
$.ajax({
url:'stringURL',
beforeSend: function(x) {
x.setRequestHeader('Authorization','username/pwd');
},
dataType:"xml",
contentType:'application/xml',
timeout:10000,
type:'POST',
success:function(data) {
alert(data);
},
error:function(XMLHttpRequest,textStatus, errorThrown) {
alert("Error status :"+textStatus);
alert("Error type :"+errorThrown);
alert("Error message :"+XMLHttpRequest.responseXML);
}
});
It seems that there is a parse error on the data fetched. You want the XMLHttpRequest to parse XML data, so the fetched URL has to return valid XML. There are several possible reasons why that works on one but fails on another platform:
-The browser request headers may be different, resulting in a different server answer. Some servers may give HTTP 200 status answers with some error message in case of problems, which doesn't parse to valid XML.
-The returned XML may be problematic and parses well on the iPhone due to quirks in the browser there but fail on another WebKit version / variant the Android uses.
-The fetched data is damaged due to other request headers, provider, proxy or other effects. For example some proxys only handle HTTP/1.0 requests, and bad behaving servers serve HTTP/1.1 with chunked encoding every time, so the XML will be damaged by the chunk headers.
For debugging purposes you can change the request to a text request and show the fetched data, or even save it to the devices SD card if possible in your application. You can then verify it has arrived intact and is in fact valid XML.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With