views:

389

answers:

2

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");
});
+2  A: 

The function is $.getJSON and not $.getJson

Darin Dimitrov
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
Is your server sending the correct MIME type: `application/json` or `application/javascript`?
Darin Dimitrov
$.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
@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
A: 

Also ensure with Firebug that you are getting valid JSON back from the server.

Andy Gaskell
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
On the Net tab in Firebug you'll be able to see all of the requests/responses.
Andy Gaskell
$.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