-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathajax.js
41 lines (41 loc) · 1.39 KB
/
ajax.js
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
var ajax = {
get: function(e, t) {
var s = new XMLHttpRequest;
s.addEventListener("readystatechange", function() {
4 == this.readyState && 200 == this.status ? t(!1, this.response, !1) : 404 == this.status && t({"code":"1","message":"page not found","status":"404"}, !1, !1)
}), s.addEventListener("progress", function(e) {
e.lengthComputable ? t(!1, !1, {
loaded: e.loaded,
fileSize: e.total
}) : t(!1, !1, !1)
}), s.open("GET", e, !0), s.send()
},
getSync:function(address){
var s=new XMLHttpRequest;
s.open("GET",address,!1);
s.send();
return s.response;
},
post: function(e, t, s) {
var n = new XMLHttpRequest;
n.addEventListener("readystatechange", function() {
4 == this.readyState && 200 == this.status ? s(!1, this.response, !1) : 404 == this.status && s({"code":"1","message":"page not found","status":"404"}, !1, !1)
}), n.addEventListener("progress", function(e) {
e.lengthComputable ? s(!1, !1, {
loaded: e.loaded,
fileSize: e.total
}) : s(!1, !1, !1)
}), n.open("POST", e, !0), n.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"), n.send(t)
},
postSync:function(ad,dt){
var a=new XMLHttpRequest;
a.open("POST",ad,!1);
a.send(dt);
return a.response;
}
,
exists: function(e) {
var t = new XMLHttpRequest;
return t.open("GET", e, !1), t.send(), 404 != t.status
}
};