为什么我的AJAX调用成功函数没有触发java脚本警报?

RJ.*_*RJ. 1 javascript ajax jquery

$.ajax({
   url: '../api/notifications/deleteNotification?userId=' + userId + '&notificationId=' + notificationId,
   type: 'DELETE',
   success: function()
   {
       CreateNotificationTree(userId);
       alert('Delete successful.');
   },
   failure: function()
   {
       alert('Delete failed.');
   }
});
Run Code Online (Sandbox Code Playgroud)

功能CreateNotificationTree(userId);上面是Ajax调用成功函数内会被触发.但是,警报并未触发.有人知道为什么吗?我也试过使用多个浏览器.

编辑 - 发现我在执行AJAX调用时遇到此错误:

Uncaught TypeError: Cannot read property 'uid' of undefined kendo.web.min.js:23
(anonymous function) kendo.web.min.js:23
p.extend.each jquery.min.js:2
p.fn.p.each jquery.min.js:2
g.extend._attachUids kendo.web.min.js:23
g.extend.init kendo.web.min.js:22
(anonymous function) kendo.web.min.js:9
p.extend.each jquery.min.js:2
p.fn.p.each jquery.min.js:2
$.fn.(anonymous function) kendo.web.min.js:9
CreateNotificationTree NotificationsTreeView.js:17
(anonymous function) NotificationsTreeView.js:60
k jquery.min.js:2
l.fireWith jquery.min.js:2
y jquery.min.js:2
d
Run Code Online (Sandbox Code Playgroud)

Sus*_* -- 5

将错误记录到您的控制台.

如果ajax方法失败,则不会看到警报,因为jQuery没有识别failure方法.

使用error回调记录错误.

也使用console.log而不是alert烦恼并停止执行流程

failure: function(){
   alert('Delete failed.');
}
Run Code Online (Sandbox Code Playgroud)

应该是

error: function(){
   alert('Delete failed.');
}
Run Code Online (Sandbox Code Playgroud)

并且使用donefail不是successerror回调作为后者,因为版本已弃用1.8

$.ajax({
    url: '../api/notifications/deleteNotification?userId=' 
               + userId + '&notificationId=' + notificationId,
    type: 'DELETE'
}).done(function () {
    CreateNotificationTree(userId);
    console.log('Delete successful.');
}).fail(function (jqXHR, status, error) {
    console.log("Error : " + error);
});
Run Code Online (Sandbox Code Playgroud)

使用arguments传递给回调的那些,你将能够查明错误.