用科尔多瓦我不能让跨域请求。 花在这个几个小时,仍然不知道什么是错的。 也许有人已经处理了这样的问题呢? 谢谢!
。 js文件:
//works fine, test.html - local file
$.get("test.html",function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
//does not do anything
$.get("http://www.stackoverflow.com",function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
项目配置文件:
..
<access origin="stackoverflow.com"/>
..
也尝试:
<access origin="www.stackoverflow.com"/>
<access origin="http://www.stackoverflow.com"/>
<access origin="*"/>
AndroidManifest.xml中:
..
<uses-permission android:name="android.permission.INTERNET" />
..
我有同样的问题......经过一番研究,我发现了一个办法做到这一点。 使用jQuery的$就做一个“GET”请求。
(在现实中,我试图访问一个SOAP WebService的,后来我发现这种方式使用POST或GET请求)
在此测试中的jsfiddle 。
你仍然需要访问的起源虽然...
OBS:您的申请将无法正常工作,除非你的网页试图让,让你做到这一点。 示例页面允许访问,所以,尽量从科尔多瓦的应用程序访问它。
$.ajax({
type: 'GET',
url: "http://anytime.ueuo.com/http-return.php",
crossDomain: true,
success: function (data, textStatus, jqXHR) {
alert("Ok!");
$("#retorno").html(data);
},
error: function (jqXHR, textStatus, errorThrown) {
alert("Wait, take a look: " + textStatus + ", " + errorThrown);
},
complete: function (jqXHR, textStatus ) {
alert("Status: " + textStatus);
}
});
OBS-2:您的代码返回错误:XMLHttpRequest的无法加载http://www.stackoverflow.com/ 。 没有“访问控制允许来源”标头出现在所请求的资源。 原产地“ 的http://本地主机:8383 ”因此不允许访问。 (02:18:52:813 |错误,JavaScript的)在的public_html / index.html中 。 这就是为什么你需要有一个预配置页面进行测试。
对不起,我的英语不好 '-'
文章来源: Cannot send cross domain requests with Cordova. Whitelisting doesn't work