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);

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.