gpt4 book ai didi

javascript - ajaxComplete 不触发

转载 作者:行者123 更新时间:2023-11-30 06:55:33 24 4
gpt4 key购买 nike

我遇到了这个问题,并不是所有的 ajaxComplete 调用都被触发了。

我的代码

$(document)
.ajaxStart(function () {
$.blockUI();
})
.ajaxComplete(function () {
$.unblockUI();
});

这是 ajaxComplete 没有触发的代码:

$('body').on('click', '.actTimeSheetApprove', function () {
var node = $(this).parents('tr');

$.ajax({
url: '/TimeSheet/Approve/',
type: 'POST',
context: this,
data: {
__RequestVerificationToken: fnGetToken(),
id: $(this).data('id')
},
success: function (data) {
if (data == 'success') {
var table = $('#tblTimeSheetApprove').DataTable();
table.row(node).remove().draw();
console.log('SUCCESS'); //I already made sure this is called
}
}
})
})

请注意,我已经确保调用了 SUCCESS 日志。

知道为什么吗?

更新:

这是我的 Controller

[HttpPost]
[ValidateAntiForgeryToken]
[ClaimAuthorize("Role", "Manager")]
public ActionResult Approve(int id)
{
_uow.TimeSheet.Approve(id, User.Identity.Name);
_uow.Save();
return Content("success");
}

这是我的控制台日志:

enter image description here

最佳答案

我猜你在 $.ajax 调用中的“语法”不正确,你错过了 complete...

成功 !== 完成

https://api.jquery.com/Ajax_Events/

通过 ajaxStart,您可以使用 loadajaxSetup 来发出请求并定义成功/错误方法的行为;

同样对于调试,尝试 ajaxStop() 并查看是否一切正常。

关于javascript - ajaxComplete 不触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32942904/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com