Skip to content

Instantly share code, notes, and snippets.

@seraekim
Created November 28, 2017 11:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seraekim/b0a149554f1657782335dffca4323a82 to your computer and use it in GitHub Desktop.
Save seraekim/b0a149554f1657782335dffca4323a82 to your computer and use it in GitHub Desktop.
front javascript get/post request
/**
*
* @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