经常用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. iOS字符串大小转换

    NSString *test = @"Hello World";            // 小写      NSString *lower = [test lowercaseSt ...

  2. ThreadPoolTaskExecutor异步的处理报警发送邮件短信比较耗时的东东

    package com.elong.ihotel.util; import org.springframework.beans.factory.DisposableBean; import org.s ...

  3. 从xml文件中读取注释

    void Main() {     string dirp=@"E:\Cread\UP4201308.bak\UP4.BAK\ExportPath\ConfigFile\";   ...

  4. Win32应用程序中文支持

    Settings--Editor---Encoding改为Windows 936 main.cpp中#include "locale.h" winmain中增加一行: setloc ...

  5. DB2 DATE类型在显示的时候,带有00:00:00,去掉的方法,使用VARCHAR()函数

    DROP VIEW DMS.V_AQ_INSURANCECLAIMS; CREATE VIEW DMS.V_AQ_INSURANCECLAIMS AS SELECT * FROM (SELECT T1 ...

  6. <Win32_1>深入浅出windows消息机制[转自crocodile_]

    上学期学习了Java ,感觉Java写一个窗口真心简单,很易上手,也就难怪很多开发人员选择Java作为自己的开发编程语言.但是由于自身对windows的热爱,让我觉得c.c++语言才是我亲睐的编程语言 ...

  7. appium自动化测试中获取toast消息的解决方法【转】

    http://blog.csdn.net/hqzxsc2006/article/details/50036911 待实践.. 解决方法:appium下切换selendroid模式去获取Android的 ...

  8. linux下对普通用户设置文件访问控命令之setfacl

    命令名 setfacl  -设置文件访问控制列表 常用用法:setfacl [-bkRd] [{-m|-x} acl参数] 目标文件名 命令的常用参数 -m 设置后续的acl参数给文件使用(常用). ...

  9. Java科普之算法剖析

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 从小白晋升,一路走来:从helloworld,到JFrame,再到Android:从城外小子,到内城 ...

  10. 在CentOS 7中安装与配置Tomcat-8方法

    安装前提 在CentOS 7中安装与配置JDK8 安装tomcat  apache-tomcat-8.0.14.tar.gz文件上传到/usr/local中执行以下操作: [root@localhos ...