我想解决一个诺言,这反过来又使一个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回调?