宝塔服务器面板,一键全能部署及管理,送你3188元礼包,点我领取

我是程序猿

注册

 

发新话题 回复该主题

ajax的重写 [复制链接]

1#
  1. $.najax = function (options) {
  2.     var opts = $.extend({
  3.         alerterror: false, alertbierror: false, cache: false, dataType: "json"
  4.     }, options);
  5.     opts.success = function (data) {
  6.         $.loading(false);
  7.         if (options.success) {
  8.             options.success(data);
  9.         }
  10.     }
  11.     opts.error = function () {
  12.         $.loading(false);
  13.         if (options.error) {
  14.             options.error();
  15.         }
  16.     }
  17.     opts.beforeSend = function () {
  18.         $.loading(true);
  19.     };
  20.     opts.complete = function () {
  21.         $.loading(false);
  22.         if (options.complete) {
  23.             options.complete();
  24.         }
  25.     };
  26.     $.ajax(opts);
  27. }
  28. //loading效果
  29. $.loading = function (bool) {
  30.     if (bool) {
  31.         document.getElementById("load").style.display = "";//显示等待效果
  32.         document.getElementById("load").style.cursor = "wait";//鼠标开始等待
  33.     } else {
  34.         document.getElementById("load").style.display = "none";//结束等待效果
  35.         document.getElementById("load").style.cursor = "default";//鼠标停止等待
  36.     }
  37. }

复制代码
分享 转发
TOP
发新话题 回复该主题