Tanaki
Tanaki

Reputation: 2635

jQuery getJSON Never Calls Success Function When Successful

I am using jQuery to retrieve json data from a server. The server responds with a json-encoded object. The problem is, after the server responds, my success function does not get called.

Here is my request:

$('form').on('submit', function(event) {
  event.preventDefault();
  $.getJSON('?getAvailableRoom', function(data, textStatus, jqXHR) {
    alert("Success!"); // doesn't happen
  });
});

Here is the response from the server:

Response Headers
Content-Type        application/json
Date                Mon, 09 Jul 2012 20:02:10 GMT
Transfer-Encoding   chunked
Via                 1.1 teleproxy01 (NetCache NetApp/6.0.3P2D5)

Request Headers
Accept  application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Host    XXXXX
Proxy-Connection    keep-alive
Referer XXXXX
User-Agent  Mozilla/5.0 (Windows NT 5.2; rv:13.0) Gecko/20100101 Firefox/13.0.1
X-Requested-With    XMLHttpRequest

Response
{'id':'AsuRC'}

Upvotes: 2

Views: 1245

Answers (1)

Kevin B
Kevin B

Reputation: 95066

Your JSON is invalid.

It should be:

Response
{"id":"AsuRC"} 

Upvotes: 7

Related Questions