【发布时间】:2021-12-12 20:02:01
【问题描述】:
根据 jQuery 文档,global Ajax event handlers 必须使用文档上的回调函数来实现。否则,本地$.ajax() 使用promises 实现事件。
有没有什么方法可以使用 promises 方法来处理全局 Ajax 事件,例如 .done()、.fail()、.always() 和 .then()?
我正在寻找一种方法来为不依赖于$(document) 的全局 ajax 事件声明事件处理程序,例如:
// current way of doing this:
// $(document).ajaxSuccess(_handleAjaxSuccess);
//
// some ideas of what it could look like:
// $.ajaxSuccess(_handleAjaxSuccess);
// $.ajax.done(_handleAjaxSuccess);
// $.ajaxSetup({ done: _handleAjaxSuccess });
【问题讨论】:
-
请详细说明您想要做什么
标签: jquery ajax events promise jquery-events