标签:timeout 延迟 urlencode else ram $.ajax data post com
var $Common = {
request: { //请求 ajaxTimeFn: { time: null, url: null, data: null }, //防止重复提交 延迟 ajax: function (url, data, callback, async) { /// <summary> /// ajax 请求 /// </summary> /// <param name="url">服务器地址</param> /// <param name="data">请求参数</param> /// <param name="callback">回调函数</param> /// <param name="async">是否同步 默认:false关闭异步 true或不设置 均为开启异步</param> /// <param name="isLoading">是否运行Loading...(运行loading会出现无法同步运行问题)</param> //防止多次提交 if ($Common.request.ajaxTimeFn.url == url && $Common.request.ajaxTimeFn.data == data) { $Common.request.ajaxTimeFn.time = setTimeout(function () { action(function () { clearTimeout($Common.request.ajaxTimeFn.time); $Common.request.ajaxTimeFn.time = null; }); }, 400); } else { action(function () { clearTimeout($Common.request.ajaxTimeFn.time); $Common.request.ajaxTimeFn.time = null; }); } $Common.request.ajaxTimeFn.url = url; $Common.request.ajaxTimeFn.data = data; function action(callback2) { /// <summary> /// 执行 /// </summary> $.ajax({ url: url, data: data, type: ‘POST‘, async: !async ? false : true, //是否同步 false:同步 true:异步 contentType: "application/x-www-form-urlencoded", dataType: "json", success: function (result, textStatus) { if ($.isFunction(callback)) { var json; try { json = JSON.parse(result); } catch (ex) { json = result; } callback(json); } //防止多次提交 if ($.isFunction(callback2)) callback2(); }, error: function (msg) { var n = ""; //防止多次提交 if ($.isFunction(callback2)) callback2(); } }); } } }
}
标签:timeout 延迟 urlencode else ram $.ajax data post com
原文地址:http://www.cnblogs.com/OleRookie/p/7516656.html