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);
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

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

Was this helpful?
0 Comments