因此,我试图从Phonegap Android应用程序内部调用我的服务器server.com/api
获取一些数据。我通过HTTP Get
方法调用它。Phonegap http GET请求返回空字符串
一切工作正常localhost
,file://
甚至在server.com
。我还将我的域名添加到3210。
现在代码:
服务器PHP
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
JS
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://server.com/api", true);
xhr.onreadystatechange = function(){
if (xhr.readyState == 4) {
if (xhr.status == 200 || xhr.status == 0) {
alert(xhr.responseText);
} else {
alert("NOPE");
}
}
};
xhr.send(null);
config.xml中
<access origin="http://server.com"/>
<preference name="phonegap-version" value="3.1.0" />
欢迎任何想法,
干杯!
编辑
我也尝试了一堆原产= “”(例如 “组合”, “ .server.com” 等)
请看这个回答: [Phonegap建立服务器不工作白名单插件](http://stackoverflow.com/questions/33651646/phonegap-build-server-not-工作白名单插件) – Camaleo