Ajax 呼叫如何在移动应用程序 (PhoneGap) 中工作,而在 PC 浏览器中却没有? [英] How Ajax call is working in mobile app (PhoneGap), but not in PC browser?

查看:17
本文介绍了Ajax 呼叫如何在移动应用程序 (PhoneGap) 中工作,而在 PC 浏览器中却没有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ajax 调用服务器页面如何在移动应用程序中完美运行(使用 PhoneGap).但是,当我在 PC 浏览器中从普通 HTML 页面运行相同的 Ajax 调用时,它不起作用.我想问题是跨域.但是,它在移动应用中的表现如何.

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.

使用 JSONP 它在个人电脑浏览器和移动应用程序中运行良好(使用 PhoneGap).但是在没有 datatype="jsonp" 的移动应用中也能正常工作.

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

推荐答案

来自 PhoneGap FAQ:

问.我想为 phonegap 创建一个应用程序,以通过 AJAX 访问外部部署的 Web 服务.我该如何解决这个问题XmlHttpRequest的跨域安全策略?

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.跨域安全策略不影响PhoneGap 应用程序.由于 html 文件是由 webkit 使用 file://协议调用的,因此安全策略不适用.(在 Android 中,您可以通过编辑 AndroidManifest.xml 向您的应用授予 android.permission.INTERNET)

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)

这篇关于Ajax 呼叫如何在移动应用程序 (PhoneGap) 中工作,而在 PC 浏览器中却没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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