2

I have this annoying problem on my app PhoneGap that the request below works fine on my web browser and my AVD, but fails on device, I keep getting readyState 0, can anyone help?

var appCredentials = "client_id=MY_CLIENT_ID&client_secret=MY_CLIENT_SECRET";

function loadVenues(){

    var url = "https://api.foursquare.com/v2/venues/search?";
    var ll = "&ll=-23.6057,-46.6662&limit=4";
    var request = url+appCredentials+ll;

    $.ajax({
        dataType: "json",
        url: request,
        success: loadVenuesSuccess,
        error: error
        });

}

function error(param1, param2, param3){
    alert(JSON.stringify(param1));
        alert(param2);
            alert(param3);
}

Please note that it works on both browser and AVD.

tomrozb
  • 25,773
  • 31
  • 101
  • 122
vrsbrazil
  • 21
  • 1
  • Could be the issue with internet connection of device. Check it. – Amol Chakane Sep 12 '13 at 11:17
  • Already checked, device´s internet is working fine. – vrsbrazil Sep 12 '13 at 12:16
  • What does logcat says? – Amol Chakane Sep 12 '13 at 12:18
  • Try using `dataType: "jsonp"`. Also can you be more specific about the version of devices you are testing and cordova version too? – Amol Chakane Sep 12 '13 at 12:29
  • I tried jsonp but it didn´t call success nor failure, I am testing using jquery-1.9.1.min.js on a Samsung Galaxy S3, here is the altered code: $.ajax({ dataType: "jsonp", url: request, success: function(data){ alert(data) }, error: function(data){ alert(JSON.stringify(data)); } }); – vrsbrazil Sep 12 '13 at 13:41
  • Here is the generated url, I load it from the device´s browser and it works, on ajax it fails: https://api.foursquare.com/v2/venues/search?client_id=CLIENT_ID&client_secret=CLIENT_SECRET&v=20130909&ll=-23.6057,-46.6662&limit=4 – vrsbrazil Sep 12 '13 at 14:00
  • Have you set your access origin? (eg ) – Dawson Loudon Sep 12 '13 at 15:57

1 Answers1

0

Had the same issue, in my case the problem was my url contained htaccess information like (http://username:mypassword@www.domain.com/.....)

took me hours to find that bug in phonegap (works on every others plattform, also the avd etc, only on the real device not.)

Not sure that is your problem, but it might give you a hint were to investigate further...

Colin
  • 101
  • 8