Created
November 28, 2017 11:24
-
-
Save seraekim/b0a149554f1657782335dffca4323a82 to your computer and use it in GitHub Desktop.
front javascript get/post request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @author srkim | |
*/ | |
cc = { | |
send: function (o, a) { | |
var h = Math.floor(1e6 * Math.random() + 1), | |
i = o.url; | |
i += "?a=" + encodeURIComponent(o.a), i += "&b=" + encodeURIComponent(o.b), i += "&c=" + encodeURIComponent(o.c), i += "&d=" + encodeURIComponent(o.d), i += "&cb=" + h, cc.ajax(i, a) | |
}, | |
ajax: function (a, $b) { | |
var b = cc.createCORSReq("GET", a); | |
b.onload = function () { | |
if(b.responseText) { | |
$b.show(); | |
} | |
}, b.send() | |
}, | |
createCORSReq: function (a, b) { | |
var c = new XMLHttpRequest; | |
return "withCredentials" in c ? c.open(a, b, !0) : "undefined" != typeof XDomainRequest ? (c = new XDomainRequest, c.open(a, b)) : c = null, c | |
} | |
}; | |
cc = { | |
send: function (o, a) { | |
var h = Math.floor(1e6 * Math.random() + 1), | |
u = o.url; | |
i = "a=" + encodeURIComponent(o.a); i += "&b=" + encodeURIComponent(o.b), i += "&c=" + encodeURIComponent(o.c), i += "&d=" + encodeURIComponent(o.d), i += "&cb=" + h, cc.ajax(u, i, a) | |
}, | |
ajax: function (a, b, c) { | |
var d = cc.createCORSReq("POST", a); | |
d.onload = function () { | |
if(d.responseText == 1) { | |
c.show(); | |
} | |
}, d.send(b) | |
}, | |
createCORSReq: function (a, b) { | |
var c = new XMLHttpRequest; | |
"withCredentials" in c ? c.open(a, b, !0) : "undefined" != typeof XDomainRequest ? (c = new XDomainRequest, c.open(a, b)) : c = null; | |
if(c) { | |
c.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8"); | |
} | |
return c | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment