[英]Ajax request working in browsers but not in phonegap
I have a cross domain request working perfectly within firefox, chrome etc as soon as i compile with phonegap it stops working 我有一个跨域请求,只要我使用phonegap编译,它就可以在Firefox,Chrome等浏览器中完美运行
Ajax: 阿贾克斯:
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();
}
This code rewrites the body hmtl and just shows the result text fetched from the server. 这段代码重写了主体hmtl,仅显示了从服务器获取的结果文本。 I did this simply for testing. 我这样做只是为了测试。 it does nothing once running in phonegap 一旦在phonegap中运行,它什么也不做
this is get.php on the server: 这是服务器上的get.php:
<?php
header("Access-Control-Allow-Origin: *");
echo "Hello world";
?>
I added this to the phonegap config.xml: 我将此添加到phonegap config.xml中:
<access origin="*" subdomains="true" />
But it still didnt change anything 但是它仍然没有改变任何东西
Any idea why this isnt working? 知道为什么这不起作用吗?
Best Regards, 最好的祝福,
Jason 杰森
在phonegap中使用ajax,您必须将特定域列入白名单,您可以在此处阅读有关其的所有信息, 请单击此处访问页面
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.