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
<script id="source" language="javascript" type="text/javascript">
$(function () {
alert("before");
$.getJson(URL,function(json){
alert("hello");
var plot = $.plot($("#placeholder"), json.data, options);
});
alert("after");
});
From stackoverflow
-
The function is $.getJSON and not
$.getJson
Santhosh S : 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 JSONDarin Dimitrov : Is your server sending the correct MIME type: `application/json` or `application/javascript`?Santhosh S : $.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 jsonlintDarin Dimitrov : @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. -
Also ensure with Firebug that you are getting valid JSON back from the server.
Santhosh S : 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 JSONAndy Gaskell : On the Net tab in Firebug you'll be able to see all of the requests/responses.Santhosh S : $.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 ?
0 comments:
Post a Comment