Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何在$.getJSON上设置beforeSend侦听器_Jquery - Fatal编程技术网

Jquery 如何在$.getJSON上设置beforeSend侦听器

Jquery 如何在$.getJSON上设置beforeSend侦听器,jquery,Jquery,我正在使用$.getJSON获取跨域ajax请求。我想在上面添加一个加载效果。 除了使用 // Loading show $.getJSON("url", function(){ //Loading hide }); 及 在$getJSON上发送侦听器之前,我如何绑定? 谢谢大家! 您只需在调用$.getJSON之前显示加载图形,并在完整函数中隐藏加载图形 ShowLoading(); $.getJSON({ ... success: getJSONSuccess });

我正在使用$.getJSON获取跨域ajax请求。我想在上面添加一个加载效果。 除了使用

// Loading show    
$.getJSON("url", function(){ //Loading hide });

在$getJSON上发送侦听器之前,我如何绑定?
谢谢大家!

您只需在调用
$.getJSON
之前显示加载图形,并在完整函数中隐藏加载图形

ShowLoading();

$.getJSON({
   ...
   success: getJSONSuccess
});

function getJSONSuccess(response) {
   // handle response
   HideLoading();
}

您需要的是
.ajaxSend()
侦听器。它将为每个Ajax调用填充一个全局事件监听器,就像您的getJSON一样。此处引用


检查这个:我的意思是我正在寻找这两个方法之外的其他方法==”
ShowLoading();

$.getJSON({
   ...
   success: getJSONSuccess
});

function getJSONSuccess(response) {
   // handle response
   HideLoading();
}
$(document).ajaxSend(function () {
    showSpinner();
}).ajaxStop(function () {
    hideSpinner();
});