jQuery的AJAX功能不能在Android的PhoneGap的应用工作 [英] jQuery's ajax function does not work in Android PhoneGap application

查看:159
本文介绍了jQuery的AJAX功能不能在Android的PhoneGap的应用工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过AJAX访问开放API的移动应用程序,它的做工精细的iPhone,但不工作的Andr​​oid PhoneGap的应用程序:

返回错误 - >中的前pression数据的错误信息为空,类型错误,结果[空]是不是对象和错误状态,parsererror

有没有遵循任何浏览器的设置需要。

我要调用的Andr​​oid PhoneGap的应用程序的Web服务:

  $。阿贾克斯({
   网址:stringURL,
   beforeSend:函数(X){
     x.setRequestHeader('授权','用户名/密码');
   },
   数据类型:XML,
   的contentType:应用程序/ XML,
   超时:10000,
   键入:POST,
   成功:功能(数据){
     警报(数据);
   },
   错误:函数(XMLHtt prequest,textStatus,errorThrown){
     警报(错误状态:+ textStatus);
     警报(错误类型:+ errorThrown);
     警报(错误信息:+ XMLHtt prequest.responseXML);
   }
});
 

解决方案

似乎没有对获取的数据解析错误。您希望XMLHtt prequest解析XML数据,因此所获取的URL必须返回有效的XML。有几个可能的原因是工程之一,但未能在其他平台上:

-The浏览器请求头可能会有所不同,导致了不同的服务器的答案。有些服务器可能给HTTP 200状态的回答与案件的问题的一些错误信息,不分析,以有效的XML。

-The返回的XML可以是有问题的,并解析以及在iPhone上由于在浏览器中有怪癖但未能在另一版本的WebKit /变体的Andr​​oid使用

-The取出的数据由于其他请求头,提供者,代理或其它影响而损坏。例如一些proxys只能处理HTTP / 1.0请求,和坏行为的服务器服务于HTTP / 1.1的分块每一次编码,因此XML将被大块头被损坏。

有关调试的目的,您可以更改请求到一个文本请求,并显示所获取的数据,甚至将它保存到设备的SD卡,如果可能的话在你的应用程序。然后,您可以验证它已经到达完好无损,实际上是在有效的XML。

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.

这篇关于jQuery的AJAX功能不能在Android的PhoneGap的应用工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆