小编Yas*_*dia的帖子

解决另一个承诺失败的承诺

我想解决一个诺言,这反过来又使一个ajax调用。无论ajax调用是否成功,都应解决诺言。我尝试了以下代码段:

new Promise(function(resolve, reject) {
  $.ajax({
    url: "nonExistentURL",
    headers: {
      "Content-Language": "en"
    },
    async: true,
    type: "DELETE",
    contentType: "application/json",
    crossDomain: true,
    dataType: "json"
  }).done(function(oSuccessData) {
    debugger;
    resolve(oSuccessData);
  }).fail(function(oData) {
    debugger;
    resolve(oData);
  });
}).then(function(oData) {
  debugger;
}).catch(function(err) {
  debugger;
});
Run Code Online (Sandbox Code Playgroud)

但是,这似乎总是在进入catch回调。为什么不进入then回调?

javascript ajax jquery promise

4
推荐指数
1
解决办法
58
查看次数

标签 统计

ajax ×1

javascript ×1

jquery ×1

promise ×1