How does an Ajax call work in a mobile application (PhoneGap), but not in a PC browser?

How to call Ajax to a server page works as a prefect in a mobile application (using PhoneGap). But, when I launch the same Ajax call from a regular HTML page in a PC browser, it does not work. I think the cross-domain problem. But how does it work in a mobile application.

Using JSONP , it works great in browser and mobile application (using PhoneGap). But in a mobile application without datatype="jsonp" also works fine.

+7
source share
4 answers

From the Frequently Asked Questions about PhoneGap :

Q. I want to create a phonegap application to access external deployable web services through AJAX. How can I solve the problem with the cross-domain security policy XmlHttpRequest?

but. Cross-domain security policies do not affect PhoneGap applications. Since html files are called by webkit with the file: // protocol, a security policy is not applied. (on Android, you can provide android.permission.INTERNET to your application by editing the AndroidManifest.xml file)

+12
source

Mobile applications (PhoneGap, Adobe AIR, Titanium, Native, etc.) have no restrictions on the same origin for XHR requests made by desktop browsers. They can make any cross-domain calls that they want. That's why it works great on the phone, not on the desktop.

JSONP works fine in both cases since it does not use XHR. It performs a cross-domain query using the <script> tag. Thus, it turns into a browser policy. JSONP can only work if the remote service returns data as a function that runs immediately.

+7
source

I assume that all WebView-based views do not have restriction rules for cross-domain XHR requests. Another way to cross-domain request is a server bridge.

+1
source

you can use iqouta to create an ajax phone call search for iqouta which is easy to use!

0
source

All Articles