简体   繁体   English

为什么我的AJAX调用成功函数未触发Java脚本警报?

[英]Why is my AJAX call success function not firing a java script alert?

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

The function CreateNotificationTree(userId); 函数CreateNotificationTree(userId); that is inside the success function of the ajax call above DOES fire. 在DOES上方执行ajax调用的成功函数中。 However, the Alert is not firing after. 但是,警报不会在之后触发。 Does anybody know why? 有人知道为什么吗? I have tried to use multiple browsers as well. 我也尝试过使用多个浏览器。

EDIT - found out I'm running into this error when the AJAX call executes: 编辑-发现执行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

Log the error to your console. 将错误记录到控制台。

You do not see the alert if ajax fails method as jQuery does not identify the failure method. 如果ajax失败方法,您将看不到警报,因为jQuery无法识别failure方法。

Use a error callback to log the error. 使用error回调记录错误。

Also use console.log instead of alert which is annoying and stops the flow of execution 还请使用console.log而不是令人讨厌的alert并停止执行流程

failure: function(){
   alert('Delete failed.');
}

supposed to be 应该是

error: function(){
   alert('Delete failed.');
}

And use done and fail instead of success and error callbacks as the latter as deprecated as of version 1.8 并使用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);
});

Use the arguments that are passed to the callbacks and you ll be able to pinpoint the error. 使用传递给回调的arguments ,您将可以查明错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM