3

I've been searching for a while for an explanation to this issue but getting no where...

I have a jQuery getJSON request:

$.getJSON("http://localhost:8080/context/json/removeEntity.html", {
    contentId : 1,
    entIndex : entityIndex
}, onRemoveEntityResponse);

Made from the URL: http://localhost:8080/context/entity.html?contentId=2 (same domain and port).

My response as seen via firebug in Firefox (5) and Chrome is empty. What's also interesting is that I have put a break point in my Java code that serves the JSON request and it is hit, but only after Firefox decides the request is complete.

I have also debugged some of the jQuery and here are some of the variables involved in the AJAX response handling (jQuery 1.5.2 un-minified):

[Line: 6651] deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] )

jqXHR: { readyState:0, responseText:"", status:0, statusText:"error", ...})
statusText: "error"
error: ""

Any ideas? Thanks in advance.

Edit:

Ignore the fact that the URL requests an HTML file, it's not really HTML, we use Tiles with Spring MVC to provide mappings to JSP files and Java controllers.

The JSON that should be returned by my Java controller is as follows (and is if I go to the URL directly):

{"oldEntityIndex":1,"isSuccess":true,"entityWasSaved":false}
Ed .
  • 6,373
  • 8
  • 62
  • 82
  • Why is it an HTML file? Also can you please show the JSON? – ChaosPandion Jul 05 '11 at 13:43
  • And Firebug tells you that the request has been successful? – polarblau Jul 05 '11 at 14:34
  • No, it is all red but there is no response code next to the request URL like there would normally be for a 200, 404, 403, etc. – Ed . Jul 05 '11 at 14:40
  • And you're sure that the server returns proper JSON? – polarblau Jul 05 '11 at 15:20
  • Fairly - I'm using a Java JSON library to output a JSON string; http://www.json.org/java/ and it shouldn't really matter at this stage anyway since the break point in my Java code gets hit after jQuery has starting handling the 'response'. – Ed . Jul 05 '11 at 15:50
  • Have you tried with relative URL? Also check whether you are getting OPTIONS request instead of GET on the server for Access Control Headers. – Jeesmon Jul 06 '11 at 15:32

1 Answers1

1

My stupidity - a jQuery plugin I had written (and included in an answer here) had a bug in it.

The plugin had removed the onclick attribute of the element that sent the AJAX request off and bound it using jQuery bind, but what I had forgotten to do with the onclick handler was return the result. Hence my onclick handler returning false and preventing the browser from following the underlying link was ignored, I guess the browser then cancelled the AJAX request since it knew it was about to move to a new page.

Wasted time! Sorry.

Community
  • 1
  • 1
Ed .
  • 6,373
  • 8
  • 62
  • 82