Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function request(url, postdata, async, method){
- var http = new XMLHttpRequest();
- var query;
- http.open(method, url, async);
- //Send the proper header information along with the request
- http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- http.onreadystatechange = function() {//Call a function when the state changes.
- if(http.readyState == 4 && http.status == 200){
- console.log("successfully request \nURL:"+url+"\n STATUS:"+http.status+"\nPOST:"+postdata+"\nAnswer:"+http.responseText)
- query = http.responseText;
- }
- else if(http.readyState == 4 && http.status >= 400 || http.status >= 300){
- console.log("send request error or network error \nURL:"+url+"\nPOST:"+postdata+"\nAnswer:"+http.responseText)
- return request(url, postdata, async, method);
- }
- }
- http.send(postdata);
- return query;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement