Answers for "javascript send json"

2

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": "[email protected]", "password": "101010"});
xhr.send(data);
Posted by: Guest on February-13-2021
1

js create json from object

JSON.stringify(the_data);
Posted by: Guest on December-18-2020
0

send json in javascript

var myObj = { "name":"Jane", "age":18, "city":"Chicago" };  // create object
var myJSON = JSON.stringify(myObj);                         // stringify
window.location = "demo.php?x=" + myJSON;                   // send to php
Posted by: Guest on August-05-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language