![](/img/trans.png)
[英]Loading JSON with ajax working in local browser, but not in the PhoneGap app
[英]AJAX post request working in browser, not on Phonegap App
當我在iOS10上使用Phonegap應用程序對其進行測試時,一個簡單的AJAX請求失敗。
代碼如下(在瀏覽器中完美運行):
if($.trim(firstname).length > 0 & $.trim(email).length > 0 & $.trim(password).length > 0) {
console.log("input checked");
$.support.cors = true;
$.ajax({
type: "POST",
url: "http://my-server.com/signup.php",
data: dataString,
crossDomain: true,
cache: false,
beforeSend: function(data) {
console.log("connecting to server");
},
//display success/fail message - put something in data on server
success: function(data, textString, xhr) {
if(data == "success") {
localStorage.login = "true";
localStorage.email = email;
mainView.router.loadPage("swipe.html");
} else if(data == 'exist') {
myApp.alert("Account already exists", "Login Failed");
}
},
error: function(xhr, ajaxOptions, errorThrown) {
console.log("error msg: ");
console.log(xhr);
console.log(errorThrown);
myApp.alert("Unknown error, please try again", "Login Failed");
},
complete: function(data) {
if(data.readyState == "0") {
console.log("unsent");
} else if(data.readyState == "4") {
console.log("done");
}
}
});
} return false;
}
我已經按照以前的許多答案中所述完全設置了config.xml文件:
<plugin name="cordova-plugin-whitelist" />
<access origin="http://my-server.com" />
etc...
顯然,由於我不是在構建應用程序,而只是在Phonegap服務器和Phonegap App上對其進行測試,因此無法禁用Apple的App Transport Security。
但是,這可能與ATS阻止了Phonegap應用本身向其他域發出的Ajax請求有關嗎? 正如我想的那樣,這需要Phonegap允許訪問所有域,而應用程序商店中可能不允許該訪問!
這是我對發生的事情的最佳猜測。 有什么想法或解決方法嗎?
新ios應用程序唯一的互聯網解決方案是將后端移至https ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.