JS

HOW TO SEND RECEIVE JSON DATA WITH JAVASCRIPT

FETCH SEND JSON DATA

01

JSON DATA var data = JSON.stringify({ name : "Jon Doe", email : "jon@doe.com" });

FETCH POST JSON fetch("URL", {   headers: { "Content-Type":      "application/json" },   method: "POST", body: data  })

SERVER RESPONSE  .then((result) =>    { return result.text(); }) .then((response) =>   { console.log(response); });

FETCH RECEIVE JSON DATA

02

FETCH fetch("URL")

SERVER RESPONSE .then((result) =>   { return result.json(); }) .then((data) =>   { console.log(data); });