简体   繁体   English

如何在调用jquery ajax成功之前调用自定义函数?

[英]How to call a custom function before jquery ajax success is called?

I am working on a mobile app that uses jQuery and BackboneJS. 我正在开发一个使用jQuery和BackboneJS的移动应用程序。 Most of the ajax calls are done using jQuery's native $.ajax function and some are done using Backbone's fetch() and save() functions. 大多数ajax调用是使用jQuery的本机$.ajax函数完成的,而某些是使用Backbone的fetch()save()函数完成的。 Now I understand that Backbone too, at a low level, calls jQuery's $.ajax function for xhr requests. 现在,我了解到Backbone在较低级别也为xhr请求调用jQuery的$.ajax函数。 What I want to know is, how can I perform some computation on my response (received from ajax calls) before actually calling the success handler? 我想知道的是,在实际调用成功处理程序之前,如何对响应(从ajax调用接收到)进行一些计算?

So what I want to know is, is there some way I can extend some jquery function such that it will execute the custom code I want, before calling the ajax success handler? 所以我想知道的是,在调用ajax成功处理程序之前,是否可以通过某种方式扩展某些jquery函数,使其执行我想要的自定义代码?

Use global Ajax events: http://api.jquery.com/Ajax_Events/ 使用全局Ajax事件: http : //api.jquery.com/Ajax_Events/

$(document).bind("ajaxSuccess", function(){
// code here
 }).bind("ajaxComplete", function(){
// code here
 });

However, I'm not sure about the event order, I didn't find you is the event precedence between local and global handlers. 但是,我不确定事件顺序,我没有发现您是本地处理程序和全局处理程序之间的事件优先级。

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

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