使动画函数在执行 $.ajax 调用时正常工作

Make animation functions work when executing $.ajax call

本文关键字:常工作 工作 调用 函数 动画 执行 ajax      更新时间:2023-09-26

我在完成这项工作时遇到了问题。 我正在使用 JQuery 2.0 ...

我试过这个,但ajaxStart对象上出现异常错误。

$.ajax({
   //Scripts here...
}).ajaxStart(function() { 
   animationStart();  // Display the busy animation...
}).ajaxStop(function() {
   animationStop();  // Hide the busy animation...
});

请参阅文档:

从jQuery 1.8开始,.ajaxStart()方法应该只附加到document

$(document).ajaxStart(animationStart).ajaxStop(animationStop);

除了杰森P说的,这样做有什么问题?

animationStart();
$.ajax({
   ..................
   done: function() {
       animationStop();
   }
});