My AJAX request is encountering issues specifically when tested on the Phonegap App using iOS10.
The code I am working with is as follows and functions perfectly in a browser:
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;
}
I have ensured that my config.xml file is configured according to previous recommendations:
<plugin name="cordova-plugin-whitelist" />
<access origin="http://my-server.com" />
etc...
Disabling Apple's App Transport Security is not an option since I am only testing the app on a Phonegap server and the Phonegap App itself.
Could ATS be blocking AJAX requests to different domains from the Phonegap App? It seems like Phonegap would need to allow access to all domains, which might not be permissible for the app store!
This is my hypothesis regarding the issue. Any suggestions or alternative solutions?