是纯粹的和传统的Ajax请求有可能对本地/混合移动应用程序?有可能、应用程序、传统、Ajax

2023-09-10 20:35:36 作者:我对贱婊过敏

我知道,使用JSONP thechnique http://en.wikipedia.org/wiki/JSONP我们可以有点让跨域Ajax请求。

I know that using JSONP thechnique http://en.wikipedia.org/wiki/JSONP we can kinda make a cross domain Ajax Request.

但是,对于这个问题,这并不算作纯和传统。

But for this question that doesn't count as "pure and traditional".

我只是想知道,如果对本机/混合应用程序也适用了同源策略

http://en.wikipedia.org/wiki/Same-origin_policy

似乎有很多混乱的这件事情。

There seems to be a lot of confusion in this matter.

我的一个朋友发誓说,他连煎茶触摸2.3.1 + PhoneGap的3对他的后端与Ajax的代理,我觉得很难相信(代理人应JSONP IMO),或者这只是需要特殊的服务器配置因为同源策略是从来没有申请'因为浏览器从来没有涉足?

A friend of mine swears that he connected Sencha Touch 2.3.1 + PhoneGap 3 to his back-end with "Ajax" proxies which I find hard to believe (proxies should be JSONP IMO), or this only requires special server config since Same Origin Policy is never applied 'cos browsers never get involved?

我知道这有点问题,可能无法在如此的精神,但我觉得对这个问题一个很好的回答将帮助了很多人,因为我一直没能找到一个。

I know this kinda question might not be in the spirit of SO but I think a good answer on this subject would help a lot of people since I've not been able to find one.

最好的问候@ code4jhon

Best regards @code4jhon

推荐答案

PhoneGap的应用程序运行的WebView不是在浏览器,因此跨起源不是一个问题与PhoneGap的应用程序,你可以执行AJAX调用的任何URL。

PhoneGap apps run in webview not in browser, so cross origin is not an issue with PhoneGap apps, you can perform AJAX calls to any URL.

要关心的唯一事情是,有一个白名单参数获得原产地的配置用来限制访问某些特定的URL。

The only thing to care of is that there is a white list parameter "access origin" in config used to restrict the access to some specific URLs.

对于老PhoneGap的版本中,默认设置访问起源是本地主机,但现在它的默认设置为*,允许访问任何URL。

For older PhoneGap versions, the default setting for access origin was localhost, but now it is set by default to "*" which allows access to any URL.

无需JSONP或CORS头与PhoneGap的。

No need for JSONP or cors headers with PhoneGap.