tension 2008-6-17 10:00
关于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官方网站资料:
[size=6]ajaxStart( callback )[/size]
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.
[b]Example[/b]:
Show a loading message whenever an AJAX request starts (and none is already active).[code]$("#loading").ajaxStart(function(){
$(this).show();
});[/code][size=6]ajaxStop( callback ) [/size]
Attach a function to be executed whenever all AJAX requests have ended.
Return value: jquery
Parameters:
callback (Function): The function to execute.
[b]Example[/b]:
Hide a loading message after all the AJAX requests have stopped.[code]$("#loading").ajaxStop(function(){
$(this).hide();
});[/code]