发新话题
打印

关于Jquery在ajax交互时显示Loading

关于Jquery在ajax交互时显示Loading

1。设置一个Div容器(假设ID为LoadingPanel,其display为none
2。设置$("#LoadingPanel").ajaxStart(function()
{
//这里设置LoadingPanel的显示.最好使用鼠标位置取得坐标,然后绝对定位,这样不管Scroll到哪都能看到Loading
});

3。$("#LoadingPanel").ajaxEnd(function(){$(this).hide();});
4。将以上方法放在document.ready的时候执行.

jquery官方网站资料:

ajaxStart( callback )
Attach a function to be executed whenever an AJAX request begins and there is none already active.

Return value: jquery
Parameters:

callback (Function): The function to execute.
Example:

Show a loading message whenever an AJAX request starts (and none is already active).
复制内容到剪贴板
代码:
$("#loading").ajaxStart(function(){
   $(this).show();
});
ajaxStop( callback )
Attach a function to be executed whenever all AJAX requests have ended.

Return value: jquery
Parameters:

callback (Function): The function to execute.
Example:

Hide a loading message after all the AJAX requests have stopped.
复制内容到剪贴板
代码:
$("#loading").ajaxStop(function(){
   $(this).hide();
});

TOP

发新话题