Why do you have JSON.stringify () your objects when sending data via AJAX?

JSON stands for javascript object designation (as I am sure you know), so why, when sending json via ajax, do you need to turn it into a string to send it? Is it just formatting, or what?

It may be in another place, if so, let me know, I will close it and translate.

Obviously, I am not looking for opinions, I would like to know the actual answer.

Just to make sure I understand, I understand what JSON.stringify () does, and its counterpart is JSON.parse (). I just want to know why use stringify.

Thanks!

+7
json javascript ajax
source share
2 answers

when sending json via ajax do you need to turn it into a string to send?

If it is not a string, then it is not JSON.

JSON is a text data format. HTTP is a text communication protocol.

JSON stands for javascript object designation

JSON is based on syntax for JavaScript literals. The JavaScript object is not JSON.

+9
source share

AJAX is all HTTP requests, which are basically β€œtext” requests to the server. This is the main reason you need to reinforce your object: in this way, it turns into text that can "travel" over HTTP.

0
source share

All Articles