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}
6
  • Why is it an HTML file? Also can you please show the JSON? Commented Jul 5, 2011 at 13:43
  • And Firebug tells you that the request has been successful? Commented Jul 5, 2011 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. Commented Jul 5, 2011 at 14:40
  • And you're sure that the server returns proper JSON? Commented Jul 5, 2011 at 15:20
  • Fairly - I'm using a Java JSON library to output a JSON string; 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'. Commented Jul 5, 2011 at 15:50

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.