1

I have a small web page that uses jQuery.ajax(). The ajax call works fine on a desktop browser (Chrome on Mac). But when I try the same web page on my Android device (Chrome on Nexus 5), I get a net::ERR_CONNECTION_REFUSED.

Here are the details of the ajax call from the Chrome Inspector when I do remote debugging with my Android device:

Request URL:http://<someURL>:<somePort>/xxxx
Request Headers CAUTION: Provisional headers are shown.
Accept:*/*
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Origin:http:http://<someURL>:<somePort>/
Referer:http://<someURL>:<somePort>/xxxx
User-Agent:Mozilla/5.0 (Linux; Android 4.4.3; Nexus 5 Build/KTU84M) AppleWebKit/537.36 (KHTML, like Gecko)

Chrome/35.0.1916.141 Mobile Safari/537.36

The Preview and Response panes of Chrome Inspector both say 'Failed to load response data'

Here is my ajax call:

$.ajax({ url: /path/, type: 'POST', data: requestObject, success: function(data) { // some code here }, error: function(jqXHR, status, error) { // some code here }, });

The error handling function always gets called in the case of Android. For desktop, the call always succeeds (success handler).

I'm a newbie with device Android web testing/debugging. Anything will help. Thanks

1 Answers1

0

Is url a remote website ? Remote ajax call are denied by default. If you want your website allowed to be called through ajax, see this answer https://stackoverflow.com/a/10143166/911718

Community
  • 1
  • 1
Kevin Labécot
  • 2,005
  • 13
  • 25
  • 2
    Thanks for your answer, Kevin. It got me to the right path: I realized that since I'm in development, the URL i'm using for ajax() inside the html file is 'localhost:...', while the address I'm using to load the page on my Android is the IP address of the same machine denoted by localhost. Somehow this worked on the desktop (can you tell why?). But I had to change 'localhost' to the IP address for the case of Android. It works now. Thanks for the speedy response! – Nodelay Heehoo Jun 22 '14 at 21:39
  • 1
    @nodelayheehoo It would be a much better idea to reference the URL relatively instead of hard-wiring your local IP address into the code. – ryanoshea Jul 23 '14 at 14:27