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

前端 未结 4 1348
伪装坚强ぢ
伪装坚强ぢ 2020-12-10 06:47

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

相关标签:
4条回答
  • 2020-12-10 07:29

    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.

    0 讨论(0)
  • 2020-12-10 07:37

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

    0 讨论(0)
  • 2020-12-10 07:43

    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)

    0 讨论(0)
  • 2020-12-10 07:43

    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.

    0 讨论(0)
提交回复
热议问题