Skip to content

Instantly share code, notes, and snippets.

@wiyoe
Created January 12, 2018 08:43
Show Gist options
  • Select an option

  • Save wiyoe/2a7aeacde3d104ea9c1f6247da21d391 to your computer and use it in GitHub Desktop.

Select an option

Save wiyoe/2a7aeacde3d104ea9c1f6247da21d391 to your computer and use it in GitHub Desktop.
Sending and Receiving JSON- Native
var xhr = new XMLHttpRequest();
xhr.open('PUT', 'myservice/user/1234');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function() {
if (xhr.status === 200) {
var userInfo = JSON.parse(xhr.responseText);
}
};
xhr.send(JSON.stringify({
name: 'John Smith',
age: 34
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment