I want to know why we need to serialize a JavaScript Object before sending to the server.
Example:
var send_data= {
id : 10,
name : 20,
school : {
name : "xyz",
location : "some place"
}
}
If I send this data without serializing, using ajax like this
$.ajax({
type: "POST",
url: "some.php",
data: { "info" : send_data}
})
Is there something wrong with this code? Because I can access all the data without unserializing...
$data = $_POST["info"];
echo $data["school"]["name"];
JSON.Stringifyif you are sending data to Server and if you are getting data from Server useJSON.Parsedataparameter the OP uses works just fine.