Chrome Extension

xhr post request with form data javascript

var data = new FormData();
data.append('username', 'username');
data.append('email', 'email');

var xhr = new XMLHttpRequest();
xhr.open('POST', 'api_url', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onload = function () {
    // YOU WILL FIND RESPONSE HERE
    console.log(this.responseText);
};
xhr.send(data);

Do you know, you can create and search your own code snippets on Devsheet. Store your code on cloud using devsheet and search using its chrome extension. Is it look cool?

The code can be used to send xhr post request from your browser with form data.

Was this helpful?
0 Comments
Never leave your website again in search of code snippets by installing our chrome extension.