I have some code in a Chrome extension that's successfully using the then()
from the xhr response of $.ajax
.
if (request && request.action === "updateTask") {
$.ajax({
type: "PUT",
url: config.updateTaskApiUrl(storage.apiKey(), request.calendarEntryId),
data: request.data,
dataType: "json"
}).then(function(data) {
sendResponse(data);
});
}
however, I now deleting a record and did the same:
if (request && request.action === "deleteTask") {
$.ajax({
type: "DELETE",
url: config.updateTaskApiUrl(storage.apiKey(), request.calendarEntryId),
dataType: "json"
}).then(function(data) {
debugger
sendResponse(data);
});
}
The debugger
line above never gets hit. I've tried done()
and putting the success: function() {}
as a key in the call too.
The response from the API is returning a 200.
Any idea why it never hits the then()
?
Looks like because of the return status code, it's interpreted as a failure. I grabbed it and inspected the status in the failure function:
$.ajax({
type: "DELETE",
url: config.updateTaskApiUrl(storage.apiKey(), request.calendarEntryId),
dataType: "json"
}).then(function(data) {
sendResponse(data);
}, function(data){
if (data.status == 200) {
sendResponse(data);
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.