Reputation: 161
After googling couple of hours i have to write that cordova(CLI 5.3.3) apps returns page not found while calling through the jquery AJAX.
I already followed all the steps in whitelist plugin(https://github.com/apache/cordova-plugin-whitelist) but still no luck.
I already include those lines in config.xml
<access origin="*" />
<allow-navigation href="*" />
Also include CSP like
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https:">
AJAX request like
$.ajax({
beforeSend: function() { $.mobile.loading("show"); }, //Show spinner
complete: function() { $.mobile.loading("hide"); }, //Hide spinner
url: weburl+"lgoin.php",
data: { email: $("#txtemail").val(), password: $("#txtpassword").val()},
type: "POST",
success: function(data) {
var response=$.parseJSON(data);
}
},
error: function (jqXHR, exception) {
var msg = '';
if (jqXHR.status === 0) {
msg = 'Not connect.\n Verify Network.';
} else if (jqXHR.status == 404) {
msg = 'Requested page not found. [404]';
} else if (jqXHR.status == 500) {
msg = 'Internal Server Error [500].';
} else if (exception === 'parsererror') {
msg = 'Requested JSON parse failed.';
} else if (exception === 'timeout') {
msg = 'Time out error.';
} else if (exception === 'abort') {
msg = 'Ajax request aborted.';
} else {
msg = 'Uncaught Error.\n' + jqXHR.responseText;
}
alert(msg);
},
});
AJAX Request always end up with massage in error callback like "Requested page not found. [404]"
Note:-- I already test webservice with Avance REST API extension and works well
Can anybody help me with this issue.
Thanks for your time and consideration in advance. -Naitik
Upvotes: 3
Views: 9741
Reputation: 794
I just added this line in application tag of AndroidManifest.xml
android:usesCleartextTraffic="true"
and it worked for me
Upvotes: 5
Reputation: 91
Basically, the thing is that you should update cordova-whitelist-plugin.
Plugin can be installed with
cordova plugin add cordova-plugin-whitelist
or by adding
<plugin name="cordova-plugin-whitelist" spec="1" />
to config.xml, and then it is configured with
<allow-navigation href="*" />
in place of the old, <access origin="*" />
tag.
please see here for details.
Upvotes: 0