Created
March 6, 2015 03:25
-
-
Save user19/75378d063d7666bde523 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function xhr(url, payload, method, headers){ | |
var x = new XMLHttpRequest(); | |
x.open(method, url, false); | |
setRequestHeader(x, method, headers) | |
x.send(payload); | |
return x; | |
} | |
function axhr(url, payload, method, headers, responseType, callback){ | |
var x = new XMLHttpRequest(); | |
x.onload = function(){callback(x);} | |
x.open(method, url); | |
setRequestHeader(x, method, headers) | |
x.responseType = responseType; | |
x.send(payload); | |
} | |
function setRequestHeader(obj, method, headers){ | |
if(method === 'POST') | |
obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | |
if(headers) | |
for(name in headers) | |
obj.setRequestHeader(name, headers[name]); | |
} | |
var xmlhttprequest = "\nxhr(url='', payload=null, method='GET', headers={});\naxhr(url='', payload=null, method='GET', headers={}, responseType='', callback);"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment