【问题标题】:jQuery ajax return undefined instead of promisejQuery ajax 返回 undefined 而不是 promise
【发布时间】:2014-02-24 18:42:43
【问题描述】:

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 会触发!

【问题讨论】:

  • 最后一个没有延迟的版本是 1.4。在这个版本中只有XMLHttpRequest object has been returned - 你确定版本 1.8.2 吗? 1.8 之后包含的任何旧版本?
  • jQuery.fn.jquery 返回“1.8.2”
  • 那我得先放弃了……:\

标签: javascript jquery ajax promise


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 2016-08-02
    • 1970-01-01
    • 2021-06-05
    • 2019-12-29
    • 2021-06-04
    • 2017-10-31
    • 2021-02-06
    • 2017-03-17
    • 2014-05-12
    相关资源
    最近更新 更多