我,只要我编译的PhoneGap它停止工作Ajax请求在浏览器中工作,但不是在PhoneGap的
阿贾克斯有一个跨域请求,在Firefox完美的工作,铬等 :
function createCORSRequest(method, url){
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr){
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined"){
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}
return xhr;
}
var request = createCORSRequest("get", "http://www.sellfast.co.za/get.php");
if (request){
request.onload = function(){
document.body.innerHTML = request.responseText;
}
request.send();
}
这代码重写主体hmtl并仅显示从服务器获取的结果文本。 我这样做只是为了测试。它什么也不做一次PhoneGap的运行
这是在服务器上get.php:
<?php
header("Access-Control-Allow-Origin: *");
echo "Hello world";
?>
我已将此添加到PhoneGap的config.xml文件:
<access origin="*" subdomains="true" />
但它仍然没有改变任何东西
任何想法,为什么这不工作?
最好的问候,
杰森
尝试你之前等待deviceready事件开始请求。 – QuickFix
你知道什么...可能工作。生病回到你身上。 – Mystx
这在模拟器中工作,但不是当我在Android设备上运行它? – Mystx