Skip to content

Instantly share code, notes, and snippets.

@djorborn
Created March 24, 2018 00:02
Show Gist options
  • Save djorborn/fd347b2f29bb12f7e1ad6206a2ee248d to your computer and use it in GitHub Desktop.
Save djorborn/fd347b2f29bb12f7e1ad6206a2ee248d to your computer and use it in GitHub Desktop.
My ajax request helper, like the one from JQUERY just very simple
function ajax(url, options) {
options.url = url;
var xhr = new XMLHttpRequest()
xhr.open((!options.type ? 'GET': options.type), options.url, true)
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
xhr.onreadystatechange = function () {
if (this.readyState == 4) {
options.success(this.response)
}
}
xhr.send("json=" + JSON.stringify(options.data))
}
/*
ajax(url, {
type: "POST",
data: JSON OBJ,
success: function(response) {
console.log(res);
}
})
*/
//I want to figure out how to not need the "json" part but still use application/x-www-form-urlencoded like JQUERY does
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment