I have been working on this for the last two days, and looking at a lot of other suggestions. Yes I can get this simple ajax request to work from within a phonegap application, both on the android emulator and on an actual android phone.
My phonegap version is (using phonegap -v) 3.0.0-0.14.3
The code I'm using is:
var url = 'http://www.thomas-bayer.com/sqlrest/CUSTOMER';
return $.ajax({
type: "GET",
url: url,
timeout: 60 * 1000
}).done(function (data) {
alert('hey');
}).fail(function (a, b, c) {
console.log(b + '|' + c);
});
The result I'm getting in the log is just:
error| at file:///android_asset/www/js/index.js:62
I added the settings to the AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
and I have the following in Config.xml
<param name="android-package" value="org.apache.cordova.core.NetworkManager" />
When I check navigator.connection.type
I get 3G
on the emulator and wifi
on the physical phone.
Any idea what else could go wrong?
UPDATE:
If I log the JSON in the first parameter of the failing function I get:
{"readyState":4,"status":404,"statusText":"error"}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…