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}
My stupidity – a jQuery plugin I had written (and included in an answer here) had a bug in it.
The plugin had removed the
onclickattribute of the element that sent the AJAX request off and bound it using jQuerybind, but what I had forgotten to do with theonclickhandler was return the result. Hence myonclickhandler returningfalseand 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.