$ .getJson回调函数不起作用

San*_*h S 0 ajax jquery getjson

我通过传递输出有效JSON作为响应的参数来调用JSP,但仍然$.getJson没有触发回调函数.JSP页面输出是

 { "data": [ [ [ 1258185480000,4.39], 
               [ 1258186020000,4.31],
               [ 1258184940000,4.39],
               [ 1258183560000,4.39]  ] ] }
Run Code Online (Sandbox Code Playgroud)

URL指向JSP页面

我的jquery代码是

<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");
});
Run Code Online (Sandbox Code Playgroud)

Dar*_*rov 9

该函数是$ .getJSON而不是$.getJson


rag*_*d33 8

$.getJSON( URL, function(data) {
  alert("hello");
});
Run Code Online (Sandbox Code Playgroud)

只不过是ajax电话的简写

$.ajax({
  dataType: "json",
  url: URL,
  data: data,
  success: function(data) {
    alert("hello");
  }
});
Run Code Online (Sandbox Code Playgroud)

重要提示:从jQuery 1.4开始,如果JSON文件包含语法错误,请求通常会以静默方式失败...例如,JSON中表示的所有字符串,无论是属性还是值,都必须用双引号括起来

来源:jquery.getjson docs