[英]Ajax request working in browsers but not in phonegap
我有一個跨域請求,只要我使用phonegap編譯,它就可以在Firefox,Chrome等瀏覽器中完美運行
阿賈克斯:
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" />
但是它仍然沒有改變任何東西
知道為什么這不起作用嗎?
最好的祝福,
傑森
在phonegap中使用ajax,您必須將特定域列入白名單,您可以在此處閱讀有關其的所有信息, 請單擊此處訪問頁面
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.