Ajax删除返回200但触发错误事件

时间:2014-06-27 13:12:18

标签: javascript jquery ajax

我已阅读大量已发布的帖子,似乎没有处理删除。 我的代码返回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)
             }
            });

2 个答案:

答案 0 :(得分:2)

问题是没有定义dataType。我添加了dataType:'text',我解决了我的问题。

答案 1 :(得分:1)

我认为这是因为type: 'DELETE'。将其更改为type: 'JSON'或将其删除。由于您返回错误格式的响应,因此会触发错误回调。如果您指定json类型并回显除json字符串之外的任何内容,则为安全。

相关问题