1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
| layui.define(['jquery'], function (exports) {
| var $ = layui.$;
|
| var $ax = function (url, success, error) {
| this.url = url;
| this.type = "post";
| this.data = {};
| this.dataType = "json";
| this.async = false;
| this.success = success;
| this.error = error;
| };
|
| $ax.prototype = {
| start: function () {
| var me = this;
| var result = "";
|
| if (this.url.indexOf("?") === -1) {
| this.url = this.url + "?jstime=" + new Date().getTime();
| } else {
| this.url = this.url + "&jstime=" + new Date().getTime();
| }
|
| $.ajax({
| type: me.type,
| url: me.url,
| dataType: me.dataType,
| async: me.async,
| data: me.data,
| beforeSend: function (data) {
|
| },
| success: function (data) {
| result = data;
| if (me.success !== undefined) {
| me.success(data);
| }
| },
| error: function (data) {
| if (me.error !== undefined) {
| me.error(data);
| }
| }
| });
|
| return result;
| },
|
| set: function (key, value) {
| if (typeof key === "object") {
| for (var i in key) {
| if (typeof i === "function")
| continue;
| this.data[i] = key[i];
| }
| } else {
| this.data[key] = (typeof value === "undefined") ? $("#" + key).val() : value;
| }
| return this;
| },
|
| setData: function (data) {
| this.data = data;
| return this;
| },
|
| clear: function () {
| this.data = {};
| return this;
| }
| };
|
| exports('ax', $ax);
| });
|
|