How Ajax call is working in mobile app (PhoneGap), but not in PC browser?

落花浮王杯 提交于 2019-12-17 19:29:11

问题


How Ajax call to server page works prefect in mobile app (using PhoneGap). But, When I run the same Ajax call from normal HTML page in PC browser it is not working. I guess the problem is cross domain. But, how it's work good in mobile app.

Using JSONP it is working fine in pc browser and mobile app (using PhoneGap). But in mobile app without datatype="jsonp" also working fine.


回答1:


From the PhoneGap FAQ:

Q. I want to create an application for phonegap to access externally deployed web services via AJAX. How can i resolve the issue with the cross-domain security policy of XmlHttpRequest?

A. The cross-domain security policy does not affect PhoneGap applications. Since the html files are called by webkit with the file:// protocol, the security policy does not apply. (in Android,you may grant android.permission.INTERNET to your app by edit the AndroidManifest.xml)




回答2:


Mobile applications (PhoneGap, Adobe AIR, Titanium, Native, etc) do not have the same-origin restriction for XHR requests that desktop browsers do. They can make any cross-domain calls that they want. That is why it works fine on the phone and not on the desktop.

JSONP works fine in both because it does not use XHR. It does a cross-domain request by use the <script> tag. So it gets around the same-origin policy of the browser. JSONP can only work though if the remote service returns the data in the form of a function that is then immediately executed.




回答3:


I guess all WebView based views has no restriction rules about cross-domain XHR requests. Another way to a cross-domain request is a server-side bridge.




回答4:


you can use iqouta to make ajax call in phonegap search for iqouta it easy to use !!



来源:https://stackoverflow.com/questions/7440725/how-ajax-call-is-working-in-mobile-app-phonegap-but-not-in-pc-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!