经常用Datatables的童鞋一定碰到过当采用服务端请求的时候,一旦后台出现异常,Datatables的会一直卡在那里,中间的正在处理的提示一直停留着。

为了能给用户更好的体验,需要对Datatables进行扩展和自定义错误处理函数。

首先到Datatables官网获取一个插件: 
http://datatables.net/plug-ins/api

jQuery.fn.dataTableExt.oApi.fnProcessingIndicator = function ( oSettings, onoff )
{
if( typeof(onoff) == 'undefined' )
{
onoff=true;
}
this.oApi._fnProcessingDisplay( oSettings, onoff );
};

该插件用于开启或关闭Datatables的正在处理提醒的消息框。 
使用方法:

oTable.fnProcessingIndicator();      // On
oTable.fnProcessingIndicator(false); // Off

修改datatables创建时的options选项:

"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback,
"timeout": 15000, // optional if you want to handle timeouts (which you should)
"error": handleAjaxError // this sets up jQuery to give me errors
} );
},

定义处理错误的函数:

function handleAjaxError( xhr, textStatus, error ) {
if ( textStatus === 'timeout' ) {
alert( 'The server took too long to send the data.' );
}
else {
alert( 'An error occurred on the server. Please try again in a minute.' );
} $('.dataTable').dataTable().fnProcessingIndicator( false );
}

在Datatables中加入错误提示功能的更多相关文章

  1. MyEclipse 10.x中拓展自动提示功能

    原文转自:MyEclipse 10.7中拓展自动提示功能 在myeclipse 9以前的版本中,我们如果要为html编辑器添加自动的代码提示可以这样操作: 1.windows-->prefere ...

  2. Eclipse中代码自动提示功能设置

    Eclipse中代码自动提示功能设置 1 打开eclipse→Windows→Preferences→Java→Editor→Content Assist: 修改Auto Activation tri ...

  3. eclipse中的代码提示功能

    Eclipse 的代码提示功能,具体配置 1. 打开Eclipse ,然后"window"→"Preferences" 2. 选择"java" ...

  4. ***PHP中error_reporting()用法详解(含codeigniter框架中屏蔽错误提示的解决方案)

    php中我们对错误的处理会常用到error_reporting函数了,大家可以看到最多的是error_reporting(E_ALL ^ E_NOTICE)了,这个到底什么意思呢,下面我来来看看. e ...

  5. 实用---eclipse中的代码提示功能

    Eclipse 的代码提示功能,具体配置 1. 打开Eclipse ,然后“window”→“Preferences” 2. 选择“java”,展开,“Editor”,选择“Content Assis ...

  6. 使用dedecms中常见错误提示及解决办法(一)

    在使用 dedecms 做网站时,常常会遇到一些棘手的问题,比如:页面图片不显示(src 的地址不对)等等. 1. 更新网站时错误 问题:Call to a member function GetIn ...

  7. pycharm中常见错误提示

    1.类中定义函方法 PyCharm 提示Method xxx may be 'static': 原因:该方法不涉及对该类属性的操作,编译器建议声明为@staticmethod

  8. android设置eclipse中的自动提示功能

    菜单window->Preferences->Java->Editor->Content Assist->Enable auto activation 选项要打上勾 (并 ...

  9. ACM中常见错误提示解析

    Output Limit Exceeded 多数发生在递归遍历的过程中,多输出了一些内容(比如说空格).Output Limit Exceeded还指如果输入某一组数据,你的程序返回的结果是一直输出某 ...

随机推荐

  1. vi编辑器的常见使用技巧

    光标移动 在普通模式下, 1.按 h 向左移动光标 按 h + 数字n 可以向右移动 n个字符   比如 h + 5  就是向左移动5个字符 2.按j向下移动光标 3.按k向上移动光标 4.按 l 向 ...

  2. URAL 1517 Freedom of Choice(后缀数组,最长公共字串)

    题目 输出最长公共字串 #define maxn 200010 int wa[maxn],wb[maxn],wv[maxn],ws[maxn]; int cmp(int *r,int a,int b, ...

  3. HDU 1671 Phone List(字符处理)

    题目 用字典树可以过,可是我写的字典树一直各种错误,,, 所以,我用了别的更简便的方法.. //去你妹的一直有问题的字典树!!! ////字典树,树的根是空的 // ////#include<i ...

  4. ios图片拉伸两种方法

    UIImage *image = [UIImage imageNamed:@"qq"]; 第一种: // 左端盖宽度 NSInteger leftCapWidth = image. ...

  5. struct 理解 (需要经常理解)

    2014.3.11 分析offviewer时,有一些问题,很基础的,但是忘记了,发现问题那就快点搞定它 以下内容参考自百度百科: (2)struct 结构体有点忘记了,要复习一下  定义一个结构的一般 ...

  6. 数论之高次同余方程(Baby Step Giant Step + 拓展BSGS)

    什么叫高次同余方程?说白了就是解决这样一个问题: A^x=B(mod C),求最小的x值. baby step giant step算法 题目条件:C是素数(事实上,A与C互质就可以.为什么?在BSG ...

  7. lintcode:寻找旋转排序数组中的最小值 II

    寻找旋转排序数组中的最小值 II 假设一个旋转排序的数组其起始位置是未知的(比如0 1 2 4 5 6 7 可能变成是4 5 6 7 0 1 2). 你需要找到其中最小的元素. 数组中可能存在重复的元 ...

  8. Java笔记——equals和==的区别

    摔在这里几次,还是记下来吧. 原文:http://www.cnblogs.com/shenliang123/archive/2012/04/16/2452156.html -------------- ...

  9. GraphicsMagick / ImageMagick缺少lib报错no decode delegate for this image format

    下载相应的lib,编译安装就行了 cd ~ #下载包 wget http://www.imagemagick.org/download/delegates/zlib-1.2.7.tar.gz wget ...

  10. 11.cadence.通孔类封装创建[原创]

    1.打开Pad Designer ---- ----- ---- ---- OK ------- ---- 回到Pad Designer internal:不管是几层板,中间层用这个就可以了: --- ...