0

1.8.2

  $.ajax({
    url: "/someurl/",
    async: true,
    dataType: 'json'
  }).done(function ( data ) {
    if( console && console.log ) {
      console.log("Sample of data: ", data);
    }
  });

导致错误“Uncaught TypeError: Cannot call method 'done' of undefined”,但请求发送和服务器响应带有数据!如果我写

  $.ajax({
    url: "/someurl/",
    async: true,
    dataType: 'json',
    success: function (data) { console.log(data); }
  });

没关系,console.log 会触发!

4

1 回答 1

0

您的错误似乎可能来自您使用响应数据的方式,因为您的代码段是正确的。

为什么不运行一个失败方法并在那里测试错误?

 $.ajax({
    url: "/someurl/",
    async: true,
    dataType: 'json'
  }).fail(function (error) {
    console.log(error);
  });

或者,检查您的网络选项卡以获取 xhr 响应预览?

于 2014-02-24T10:42:43.800 回答