cordova - AJAX Request from Phonegap Android fails -


i have been working on last 2 days, , looking @ lot of other suggestions. yes can simple ajax request work within phonegap application, both on android emulator , on actual android phone.

my phonegap version (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 log just:

error| @ file:///android_asset/www/js/index.js:62

i added settings 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 have following in config.xml

<param name="android-package" value="org.apache.cordova.core.networkmanager" /> 

when check navigator.connection.type 3g on emulator , wifi on physical phone.

any idea else go wrong?

update: if log json in first parameter of failing function get:

{"readystate":4,"status":404,"statustext":"error"} 

you should whitelist domain in order ajax calls work.

add line config file -:

<access origin="*" /> 

phonegap's default policy blocks network access unless specified otherwise. above line disable security restriction. can more specific in allowing domains bypass security feature including domain name in config file so

<access origin="http://yourdomain" /> 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -