错误处理
当Ajax调用发生错误时,回调函数参数result会存在error属性,通常通过这个属性判断是否出现错误.
function
onDivComplete(result)
{
// alert(result.error);
var msg = "" ;
if (result.error != null )
{
msg += ( " 发生异常:<br/> " );
msg += ( " 异常类型: " + result.error.Type + " <br/> " );
msg += ( " 异常信息: " + result.error.Message + " <br/> " );
msg += ( " 异常堆栈信息: " + result.error.Stack + " <br/> " );
msg += ( " 异常目标站点: " + result.error.TargetSite + " <br/> " );
msg += ( " 异常源: " + result.error.Source + " <br/> " );
document.getElementById( " msg " ).innerHTML = msg;
}
}
{
// alert(result.error);
var msg = "" ;
if (result.error != null )
{
msg += ( " 发生异常:<br/> " );
msg += ( " 异常类型: " + result.error.Type + " <br/> " );
msg += ( " 异常信息: " + result.error.Message + " <br/> " );
msg += ( " 异常堆栈信息: " + result.error.Stack + " <br/> " );
msg += ( " 异常目标站点: " + result.error.TargetSite + " <br/> " );
msg += ( " 异常源: " + result.error.Source + " <br/> " );
document.getElementById( " msg " ).innerHTML = msg;
}
}
也可以使用默认处理函数,这样就可以为错误处理提供统一的函数
AjaxPro.onError
=
function
(error)
{
alert( " 错误: " + error.Message);
}
{
alert( " 错误: " + error.Message);
}
超时处理
AjaxPro.onTimeout
=
function
()
{
alert( " 超时 " );
}
Loading效果
{
alert( " 超时 " );
}
AjaxPro.onLoading
=
function
(b) {
// window.status = b ? "Loading
" : "";
document.getElementById( " LoadingBar " ).style.display = b ? " inline " : " none " ;
}
注意的是上述三个方法必须在AjaxPro加载的4个js文件之后,否则会出错
// window.status = b ? "Loading
![](https://i-blog.csdnimg.cn/blog_migrate/b854634c0904529d4018c4c3336be836.gif)
document.getElementById( " LoadingBar " ).style.display = b ? " inline " : " none " ;
}
服务器端缓存
[AjaxPro.AjaxMethod]
[AjaxPro.AjaxServerCache( 10 )] /* Cache Result 10 s */
public DateTime GetServerCachedTime()
{
return DateTime.Now;
}
[AjaxPro.AjaxServerCache( 10 )] /* Cache Result 10 s */
public DateTime GetServerCachedTime()
{
return DateTime.Now;
}