The function is $. GetJSON and not $.getJson.
Up vote -2 down vote favorite share g+ share fb share tw.
I am calling a JSP by passing parameters which outputs a valid JSON as response, but still the $. GetJson callback function is not getting fired. JSP page output is { "data": 1258185480000,4.39, 1258186020000,4.31, 1258184940000,4.39, 1258183560000,4.39 } The URL points to the JSP page My jquery code is $(function () { alert("before"); $.
GetJson(URL,function(json){ alert("hello"); var plot = $. Plot($("#placeholder"), json. Data, options); }); alert("after"); }); jquery ajax getjson link|improve this question edited Nov 16 '09 at 8:01Stu Thompson10.2k63282 asked Nov 16 '09 at 7:57Santhosh S52211 69% accept rate.
1 I changed to getJSON and tried, still the callback did not get triggered. How to validate json in firebug? I verified in Jsonlint that the response from JSP is a valid JSON – Santhosh S Nov 16 '09 at 8:28 Is your server sending the correct MIME type: application/json or application/javascript?
– Darin Dimitrov Nov 16 '09 at 8:34 $. Ajax({ type: "GET", url: URL, dataType: "json", success: function(results){ alert("Success! "); }, error: function(XMLHttpRequest, textStatus, errorThrown){ alert(textStatus); alert(errorThrown); } }); I get a parse error when I use $.
Ajax instead of $.getJSON. The data I get back from JSP is { "data": 1258185480000,4.39, 1258186020000,4.31, 1258184940000,4.39, 1258183560000,4.39 } I have verified that the JSON is proper in jsonlint – Santhosh S Nov 16 '09 at 9:32 1 @Santhosh, you need to set the proper Content-Type header in your JSP page. Please verify with FireBug that when you perform the request, the server sends Content-Type: application/json header.
– Darin Dimitrov Nov 16 '09 at 10:47.
Also ensure with Firebug that you are getting valid JSON back from the server.
I changed to getJSON and tried, still the callback did not get triggered. How to validate json in firebug? I verified in Jsonlint that the response from JSP is a valid JSON – Santhosh S Nov 16 '09 at 8:30 1 On the Net tab in Firebug you'll be able to see all of the requests/responses.
– Andy Gaskell Nov 16 '09 at 9:16 $. Ajax( { type: "GET", url: URL, dataType: "json", success: function(results){ alert("Success! "); }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert(textStatus); alert(errorThrown); } }); I get a parse error when I use $.
Ajax instead of $.getJSON. The data I get back from JSP is { "data": 1258185480000,4.39, 1258186020000,4.31, 1258184940000,4.39, 1258183560000,4.39 } I have verified that the JSON is proper in jsonlint. How to find what the parse error is?
– Santhosh S Nov 16 '09 at 9:34.
I just spent about two hours on this. I found another post that discusses the difference between $. GetJSON and $.
Get and how there really isn't any. So I swapped out my getJSON() for get() and it worked. (Also want to mention that I had also verified everything else was working by logging from the rails action and logging what I could from the javascript outside the callback function.
).
I believe the different between $. GetJSON and $. Get is in the content type (JSON vs XML).
– Mark Good Jan 15 at 2:05.