only text data can be allowed. JSON is text, we are able toÂ
convert any javascript object into JSON, then send JSON to server.
Likewise we can convert any JSON received from server intoÂ
javascript objects. So this his how we can do things with javascript
objects without parsing and translations hassles.
Following is a example shows how to send and receive data using Json -Â
When sending, If you have data in a JavaScript object, convert theÂ
object into JSON and send it to server:Â
var theObj = {name: "Mridul", age: 32, city: "California"};
var theJson = JSON.stringify(theObj);
window.location = "demo_json.php?x=" + theJson;
When receiving data, you get data in JSON format, then convert itÂ
into a JavaScript object :
var theJson = '{"name":"Rony", "age":31, "city":"New York"}';
var theObj = JSON.parse(theJson);
document.getElementById("demos").innerHTML = theObj.name;
So finally, JSON format is text only, it can be sent easily to and fromÂ
a server.Â
Hope you liked it, don't forget to share and like it.
Â