显示使用jQuery,同时使一个AJAX请求加载条加载、jQuery、AJAX

2023-09-10 13:18:50 作者:那年夏天丶那场雨

我在做一个Ajax请求用jQuery这样的:

I'm making a AJAX request with jquery like:

$.get('/Stuff.php', function (data) {
    $('#own').html(data);
});

而这个数据是加载我想显示在页面的顶部有一个小的文本(这只是说,载入中...)的没有阻止它

如何做到这一点?

推荐答案

3nigma是在正确的轨道,但有一个细节错了,至少在一般情况下。

3nigma is on the right track, but got one detail wrong, at least in the general case.

使用ajaxSetup只提供默认值,如果以后你作出这样的指定自己的回调beforeSend(即你需要设置一些特定的头文件)或完整(要同时处理成功和错误的一样),他们将覆盖一些Ajax调用那些在ajaxSetup,你的负荷指标将打破。

Using ajaxSetup only provides defaults, if later you make some ajax calls that specify their own callbacks for beforeSend (i.e. you need to set some specific headers) or complete (you want to handle both success and error the same) they will override the ones in ajaxSetup and your loading indicator will break.

相反,使用全局AJAX事件(的