-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwuchubuzai-1.0.0.full.js
58 lines (56 loc) · 1.77 KB
/
wuchubuzai-1.0.0.full.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*! wuchubuzai api javascript v1.0.0 http://www.wuchubuzai.com/ */
function getAPIUrl(env) {
if(typeof env=="undefined" || env == "production") {
return "http://api.wuchubuzai.com";
} else {
return "http://" + env + ".api.wuchubuzai.com";
}
}
function wuchu_rest_api(env, resource, action, query, callback, debug) {
if (typeof resource == "undefined") { throw "resourceRequired"; }
try {
var url = getAPIUrl(env) + '/' + resource + '/';
if ($.browser.msie) {
var xdr = new XDomainRequest();
if (query !== null) {
if (action != "GET") {
xdr.open(action, url);
xdr.send($.param(query));
} else {
xdr.open(action, url + "?" + $.param(query));
}
} else {
xdr.open(action, url);
}
xdr.onload = function() {
var data = $.parseJSON(this.responseText);
callback(data);
};
xdr.send();
} else {
if (query !== null) {
$.ajax({
url: url,
data: query,
type: action,
success: function(data) {
if (debug) console.log(data);
callback(data);
}
});
} else {
console.log(query);
$.ajax({
url: url,
type: action,
success: function(msg) {
if (debug) console.log(data);
callback(data);
}
});
}
}
} catch (e) {
console.log(e);
}
}