我已阅读大量已发布的帖子,似乎没有处理删除。 我的代码返回200状态,但发生错误事件...
$.ajax({
type: 'DELETE',
url: '/' + type + '/' + name,
success: function() {
window.alert(type + " " + name + " successful");
},
error: function(xhr, status) {
alert(xhr.status);
alert('Failed to delete ' + type + ' ' + name)
}
});
答案 0 :(得分:2)
问题是没有定义dataType。我添加了dataType:'text',我解决了我的问题。
答案 1 :(得分:1)
我认为这是因为type: 'DELETE'
。将其更改为type: 'JSON'
或将其删除。由于您返回错误格式的响应,因此会触发错误回调。如果您指定json
类型并回显除json字符串之外的任何内容,则为安全。