Skip to content

Instantly share code, notes, and snippets.

@jcbagtas
Created August 30, 2016 09:00
Show Gist options
  • Save jcbagtas/354321c0d7ccfdeca2b3d4ed50590dd3 to your computer and use it in GitHub Desktop.
Save jcbagtas/354321c0d7ccfdeca2b3d4ed50590dd3 to your computer and use it in GitHub Desktop.
Simple Native AJAX
var data= {var:"val"}
xhr = new XMLHttpRequest();
xhr.open('POST', 'url');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function() {
if (xhr.status === 200){
console.log(xhr.responseText);
}else if (xhr.status !== 200){
console.log('Failed ' + xhr.status);
}
};
xhr.send(JSON.stringify(data));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment