|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- /*
- * 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园(http://www.learun.cn)
- * Copyright (c) 2013-2018 北京泉江科技有限公司
- * 创建人:陈彬彬
- * 日 期:2017.03.16
- * 描 述:ajax操作方法
- */
- (function ($, learun) {
- "use strict";
- var httpCode = {
- success: 200,
- fail: 400,
- exception: 500
- };
- var exres = { code: httpCode.exception, info: '通信异常,请联系管理员!' }
- $.extend(learun, {
- // http 通信异常的时候调用此方法
- httpErrorLog: function (msg) {
- learun.log(msg);
- },
- // http请求返回数据码
- httpCode: httpCode,
- // get请求方法(异步):url地址,callback回调函数
- httpAsyncGet: function (url, callback) {
- $.ajax({
- url: url,
- type: "GET",
- dataType: "json",
- async: true,
- cache: false,
- success: function (data) {
- if (data.code == learun.httpCode.exception) {
- learun.httpErrorLog(data.info);
- data.info = '系统异常,请联系管理员!';
- }
- callback(data);
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- learun.httpErrorLog(textStatus);
- callback(exres);
- },
- beforeSend: function () {
- },
- complete: function () {
- }
- });
- },
- httpAsyncGetWithParam: function (url, param, callback) {
- $.ajax({
- url: url,
- type: "GET",
- dataType: "json",
- data: param,
- async: true,
- cache: false,
- success: function (data) {
- if (data.code == learun.httpCode.exception) {
- learun.httpErrorLog(data.info);
- data.info = '系统异常,请联系管理员!';
- }
- callback(data);
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- learun.httpErrorLog(textStatus);
- callback(exres);
- },
- beforeSend: function () {
- },
- complete: function () {
- }
- });
- },
- // get请求方法(同步):url地址,param参数
- httpGet: function (url, param) {
- var res = {};
- $.ajax({
- url: url,
- data: param,
- type: "GET",
- dataType: "json",
- async: false,
- cache: false,
- success: function (data) {
- if (data.code == learun.httpCode.exception) {
- learun.httpErrorLog(data.info);
- data.info = '系统异常,请联系管理员!';
- }
- res = data;
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- learun.httpErrorLog(textStatus);
- },
- beforeSend: function () {
- },
- complete: function () {
- }
- });
- return res;
- },
- // post请求方法(异步):url地址,param参数,callback回调函数
- httpAsyncPost: function (url, param, callback) {
- $.ajax({
- url: url,
- data: param,
- type: "POST",
- dataType: "json",
- async: true,
- cache: false,
- success: function (data) {
- if (data.code == learun.httpCode.exception) {
- learun.httpErrorLog(data.info);
- data.info = '系统异常,请联系管理员!';
- }
- callback(data);
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- learun.httpErrorLog(textStatus);
- callback(exres);
- },
- beforeSend: function () {
- },
- complete: function () {
- }
- });
- },
- // post请求方法(同步步):url地址,param参数,callback回调函数
- httpPost: function (url, param, callback) {
- $.ajax({
- url: url,
- data: param,
- type: "POST",
- dataType: "json",
- async: false,
- cache: false,
- success: function (data) {
- if (data.code == learun.httpCode.exception) {
- learun.httpErrorLog(data.info);
- data.info = '系统异常,请联系管理员!';
- }
- callback(data);
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- learun.httpErrorLog(textStatus);
- callback(exres);
- },
- beforeSend: function () {
- },
- complete: function () {
- }
- });
- },
- // ajax 异步封装
- httpAsync: function (type, url, param, callback) {
- $.ajax({
- url: url,
- data: param,
- type: type,
- dataType: "json",
- async: true,
- cache: false,
- success: function (res) {
- if (res.code == learun.httpCode.success) {
- callback(res.data);
- }
- else {
- learun.httpErrorLog(res.info);
- callback(null);
- }
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- learun.httpErrorLog(textStatus);
- callback(null);
- },
- beforeSend: function () {
- },
- complete: function () {
- }
- });
- },
- //同步执行
- httpSync: function (type, url, param, callback) {
- $.ajax({
- url: url,
- data: param,
- type: type,
- dataType: "json",
- async: false,
- cache: false,
- success: function (res) {
- if (res.code == learun.httpCode.success) {
- callback(res.data);
- }
- else {
- learun.httpErrorLog(res.info);
- callback(null);
- }
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- learun.httpErrorLog(textStatus);
- callback(null);
- },
- beforeSend: function () {
- },
- complete: function () {
- }
- });
- },
-
- deleteForm:function (url, param, callback) {
- learun.loading(true, '正在删除数据');
- learun.httpAsyncPost(url, param, function (res) {
- learun.loading(false);
- if (res.code == learun.httpCode.success) {
- if (!!callback) {
- callback(res);
- }
- learun.alert.success(res.info);
- }
- else {
- learun.alert.error(res.info);
- learun.httpErrorLog(res.info);
- }
- layer.close(layer.index);
- });
- },
- postForm:function (url, param, callback) {
- learun.loading(true, '正在提交数据');
- learun.httpAsyncPost(url, param, function (res) {
- learun.loading(false);
- if (res.code == learun.httpCode.success) {
- if (!!callback) {
- callback(res);
- }
- learun.alert.success(res.info);
- }
- else {
- learun.alert.error(res.info);
- learun.httpErrorLog(res.info);
- }
- layer.close(layer.index);
- });
- },
- getForm: function (url,callback) {
- learun.loading(true, '请稍后');
- learun.httpAsyncGet(url, function (res) {
- learun.loading(false);
- if (res.code == learun.httpCode.success) {
- if (!!callback) {
- callback(res);
- }
- learun.alert.success(res.info);
- }
- else {
- learun.alert.error(res.info);
- learun.httpErrorLog(res.info);
- }
- layer.close(layer.index);
- });
- },
- //提交数据不提示正在提交
- postFormSilence: function (url, param, callback) {
- learun.httpAsyncPost(url, param, function (res) {
- learun.loading(false);
- if (res.code == learun.httpCode.success) {
- if (!!callback) {
- callback(res);
- }
- }
- else {
- learun.alert.error(res.info);
- learun.httpErrorLog(res.info);
- }
- });
- }
- });
-
- })(window.jQuery, top.learun);
|