在Datatables中加入错误提示功能
经常用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中加入错误提示功能的更多相关文章
- MyEclipse 10.x中拓展自动提示功能
原文转自:MyEclipse 10.7中拓展自动提示功能 在myeclipse 9以前的版本中,我们如果要为html编辑器添加自动的代码提示可以这样操作: 1.windows-->prefere ...
- Eclipse中代码自动提示功能设置
Eclipse中代码自动提示功能设置 1 打开eclipse→Windows→Preferences→Java→Editor→Content Assist: 修改Auto Activation tri ...
- eclipse中的代码提示功能
Eclipse 的代码提示功能,具体配置 1. 打开Eclipse ,然后"window"→"Preferences" 2. 选择"java" ...
- ***PHP中error_reporting()用法详解(含codeigniter框架中屏蔽错误提示的解决方案)
php中我们对错误的处理会常用到error_reporting函数了,大家可以看到最多的是error_reporting(E_ALL ^ E_NOTICE)了,这个到底什么意思呢,下面我来来看看. e ...
- 实用---eclipse中的代码提示功能
Eclipse 的代码提示功能,具体配置 1. 打开Eclipse ,然后“window”→“Preferences” 2. 选择“java”,展开,“Editor”,选择“Content Assis ...
- 使用dedecms中常见错误提示及解决办法(一)
在使用 dedecms 做网站时,常常会遇到一些棘手的问题,比如:页面图片不显示(src 的地址不对)等等. 1. 更新网站时错误 问题:Call to a member function GetIn ...
- pycharm中常见错误提示
1.类中定义函方法 PyCharm 提示Method xxx may be 'static': 原因:该方法不涉及对该类属性的操作,编译器建议声明为@staticmethod
- android设置eclipse中的自动提示功能
菜单window->Preferences->Java->Editor->Content Assist->Enable auto activation 选项要打上勾 (并 ...
- ACM中常见错误提示解析
Output Limit Exceeded 多数发生在递归遍历的过程中,多输出了一些内容(比如说空格).Output Limit Exceeded还指如果输入某一组数据,你的程序返回的结果是一直输出某 ...
随机推荐
- POJ 2480 Longge's problem (积性函数,欧拉函数)
题意:求∑gcd(i,n),1<=i<=n思路:f(n)=∑gcd(i,n),1<=i<=n可以知道,其实f(n)=sum(p*φ(n/p)),其中p是n的因子.为什么呢?原因 ...
- HDU 1428 漫步校园(记忆化搜索,BFS, DFS)
漫步校园 http://acm.hdu.edu.cn/showproblem.php?pid=1428 Problem Description LL最近沉迷于AC不能自拔,每天寝室.机房两点一线.由于 ...
- HDU 2084 数塔(动态规划)
数塔 http://acm.hdu.edu.cn/showproblem.php?pid=2084 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描 ...
- POJ 1279 Art Gallery(半平面交求多边形核的面积)
题目链接 题意 : 求一个多边形的核的面积. 思路 : 半平面交求多边形的核,然后在求面积即可. #include <stdio.h> #include <string.h> ...
- C#中String跟string的“区别”
string是c#中的类,String是.net Framework的类(在C# IDE中不会显示蓝色) C# string映射为.net Framework的String 如果用string,编译器 ...
- 编程实现linux下的shell
/************************************************************************* > File Name: Kris_shel ...
- JavaScript基础之函数与数组
函数 函数的基本概念 为完成某一功能的程序指令(语句)的集合,称为函数.有的程序员把函数称为方法,希望大家不要被这两个名词搞晕了. 函数分为:自定义函数.系统函数(经常查看js帮助手册). j ...
- Axis2学习的第一天
按照下面,分别建2个工程,一个client(客户端),一个server(服务端) 先实现服务端: 1.编写services.xml文件,该文件是放在aar文件里的\META-INF目录下的: < ...
- sql openrowset
select * from openrowset('sqloledb','ip';'user';'pwd','exec 库..过程')
- 重温《js权威指南》 第4、5、6章
第四章 表达式和运算符 4.2 对象和数组的初始化表达式 数组: [] [3,7] [1+2,3+4] [[1,2,3,],[4,5,6],[7,8, ...