Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to send json in js with post

// Sending and receiving data in JSON format using POST method
//
var xhr = new XMLHttpRequest();
var url = "url";
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
    if (xhr.readyState === 4 && xhr.status === 200) {
        var json = JSON.parse(xhr.responseText);
        console.log(json.email + ", " + json.password);
    }
};
var data = JSON.stringify({"email": "hey@mail.com", "password": "101010"});
xhr.send(data);
Comment

PREVIOUS NEXT
Code Example
Javascript :: Datatable Change page size for pdf 
Javascript :: javascript add div before element 
Javascript :: detect button click jquery 
Javascript :: jquery scroll to id 
Javascript :: how to convert string to int a array in javascript 
Javascript :: open google map with latitude and longitude javascript 
Javascript :: javascript change element class 
Javascript :: javascript search in array of strings 
Javascript :: getting user input in node js 
Javascript :: javascript button go to url 
Javascript :: js convert set to array 
Javascript :: unique array javascript es6 Map 
Javascript :: Generate random whole numbers javascript 
Javascript :: js get paste text 
Javascript :: npm run test:coverage command in jest 
Javascript :: slice until character javascript 
Javascript :: how to make javascript progarm that randomly displayes a word 
Javascript :: Check if a JavaScript string is a URL 
Javascript :: nodejs 16 install 
Javascript :: javascript simulate key press 
Javascript :: fast xml parser nodejs 
Javascript :: laravel jquery ajax post csrf 
Javascript :: props.history.push with data 
Javascript :: nombre random js 
Javascript :: javascript trim each element in array 
Javascript :: get link js 
Javascript :: send message to all servers discord.js 
Javascript :: remove menu bar electron 
Javascript :: missing from-clause entry for table sequelize limit 
Javascript :: check if an id exists javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =