1

I'm trying to access a REST Web Service from a HTML/JavaScript application. I'm accessing both the web application and the Web Service via Apache HTTPD 2.2. The Web Service GET method does work (executes and returns data) when called directly in a browser. The Web Service never receives the request when the call is attempted from the web application.

The web service URL is

http://127.0.0.1/pbws/all/

The web page that is calling it is

http://127.0.0.1/~myusername/phonebook/

I don't believe my problem is the Same Origin Policy as explained on Wikipedia ( http://en.wikipedia.org/wiki/Same_origin_policy ) I'm using the same host, protocol and port for both the web application and the called Web Service.

The call that is failing is:

getAll = function (callback) {
   $.ajax({
       type: "GET",
       url: "http://127.0.0.1/pbws/all/",
       dataType: "json",
       async: true,
       success: function (data, textStatus, jqXHR) {
          callback(data);
       },
       error: function (jqXHR, textStatus, errorThrown) {
          console.dir(jqXHR);
          alert('getAll error: ' + textStatus);
       }
   });
};

The success is never called, only error. With a break point set, jqXHR doesn't contain any helpful information that I can see, textStatus = "error" and errorThrown is blank. The Chrome Developer Tools/Network tab shows the status as "(failed)".

I've tested this with both Chrome 23 and Firefox 16 on Windows 7. Any ideas as to what the problem can be or how to debug this further?

Jim
  • 83
  • 9
  • May be have a look on this .. http://stackoverflow.com/questions/377644/jquery-ajax-error-handling-show-custom-exception-messages – admoghal Nov 19 '12 at 03:20
  • What is `http://127.0.0.1/pbws/all/` returning – Musa Nov 19 '12 at 03:20
  • and you're able to browse to the page OK? http://127.0.0.1/pbws/all/ – davehale23 Nov 19 '12 at 03:20
  • 2
    Great question, I guess the first thing I would ask is, if you load the page in browser, does it respond with a 200? Also, does chrome give you an error code to work with. i.e. 500, 404? Maybe try and change the dataType to jsonp, and also considerlooking in the "console" tab, maybe it gives a more detailed error there. – OneChillDude Nov 19 '12 at 03:21
  • 1
    what is the http status of the failed response – Arun P Johny Nov 19 '12 at 03:29
  • When I call it directly in a browser or use the Chrome XHR Browser plugin, the HTTP Status is 200 and the payload is the correct JSON I expect. When I use the above jQuery $.ajax() command the command never gets to the web service (the web service logging code doesn't get executed). – Jim Nov 19 '12 at 03:36
  • But you can get the response status using chrome network tab – Arun P Johny Nov 19 '12 at 03:46
  • Thanks admoghal but the request never gets to the web service. I can run the web service in a debug mode and see the request never gets to it. The request appears to never get out of the web application which would make me suspect Same Origin Policy but both (web app/web service) are on the same host/port/protocol. Arun, the request never gets to the web service so there isn't a http status. – Jim Nov 19 '12 at 03:48
  • I thought that Chrome would report an error (in one of the development tool tabs, presumably console or network) if there was a Same origin policy problem. – jdigital Nov 19 '12 at 03:58
  • Arun, as I wrote in the original question above, The Chrome Developer Tools/Network tab shows the status as "(failed)". – Jim Nov 19 '12 at 03:59

1 Answers1

0

It was appcache that caused my jQuery Ajax calls to fail. With the appcache directive commented out in index.html the REST WS calls are working fine.

I'm now testing the suggestions in How do i allow json requests when using HTML5's appcache feature?

Community
  • 1
  • 1
Jim
  • 83
  • 9