在jQuery中捕获所有ajax请求 [英] catch all ajax requests in jquery

查看:282
本文介绍了在jQuery中捕获所有ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想每次发送ajax请求时显示一个正在加载"进度栏.是否有可能在任何时候使用jQuery发送ajax请求时得到通知?

I'm wanting to show a "Loading" progress bar every time an ajax request is sent. Is it possible to be notified ANYTIME an ajax request is sent using jQuery?

推荐答案

您可以使用 $.ajaxSetup() 方法设置将应用于整个页面的全局AJAX属性:

You could use the $.ajaxSetup() method to set global AJAX properties that will apply for the entire page:

$.ajaxSetup({
    beforeSend: function() {
        // show progress spinner
    },
    complete: function() {
        // hide progress spinner
    }
});

这篇关于在jQuery中捕获所有ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆