Recently, I encountered an issue with Ajax in my Phonegap development. Previously, it worked perfectly but now when I call the Ajax function, nothing happens. Here are the steps I have taken to troubleshoot:
1) I edited the config.xml file and added the following lines:
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
2) I made changes to the AndroidManifest.xml file as follows:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permissions.NETWORK_ACCESS" />
3) Switched from using JSON to JSONP, which resulted in a 404 error.
4) Verified that URLs and parameters are correct as they were before, ruling out any issues here.
5) The APK build is functioning properly on all Android devices.
6) Attempted to resolve the problem by re-installing the Phonegap app and resetting the Android device to factory data.
7) Below is an example of my Ajax code:
app.ajax = {
load: function(method, url, data, onSuccess) {
var beforeSend = function() {
$('body').append($('<i class="loading-icon"></i>'));
};
var onComplete = function() {
$('.loading-icon').remove();
};
var onError = function(jqXHR, textStatus, errorThrown){
console.log(jqXHR);
};
$.ajax({
method: method,
url: url,
data: data,
beforeSend: beforeSend,
success: onSuccess,
complete: onComplete,
error: onError
});
}};
8) Node version: v0.10.25 Cordova version: 5.1.1