android - Cordova app timeout when connecting to local server using ajax -
i've searched high , low try , solve problem no avail. trying connect phonegap app server hosted locally on machine, times out. used this code assist me in creating simple app , copied sam croft's code completely. still times out. if connect php script on samcroft, app works , can retrieve data app, if replace url mine times out. php script runs in browser, not in android virtual device. makes no difference whether add http://127.0.0.1* whitelist or not. oddly(?) if not add http://samcroft.co.uk* whitelist app runs , retrieves data when run script on samcroft.co.uk. developing in eclipse , using cordova 2.6.0. , jquery 1.9.1. have tried older version of these files same result.
with url in js code below works perfectly, when replace url 'http://127.0.0.1/landmarks.php' timeout error. i've tried adding port number url same error. i've tried using 'http://localhost/landmarks.php' same error. (the 2 landmark.php files identical, except mine connects local mysql server).
the js code:
$.ajax({ url: 'http://samcroft.co.uk/demos/updated-load-data-into-phonegap/landmarks.php', datatype: 'jsonp', jsonp: 'jsoncallback', timeout: 5000, success: function(data, status){ $.each(data, function(i,item){ var landmark = '<h1>'+item.name+'</h1>' + '<p>'+item.latitude+'<br>' + item.longitude+'</p>'; output.append(landmark); }); }, error: function(xhr, ajaxoptions, thrownerror){ alert(ajaxoptions); }
it sounds testing emulator. if case, localhost , 127.0.0.1 not work because address refers local machine, in case, actual emulator itself. instead should use 10.0.2.2, acts "bridge" development machine/server hosting script. can read more here: explain why external samecroft site works.
Comments
Post a Comment