1. Receiving data
Ajax receives data through the Xhr.responsetext property, which is a property that is not a method, and this property gets the data as a string.
2. String content
When the server sends data such as a jsonresponse ({' name ': ' Tim ', ' sex ': ' Male ') (Django Server), the front-end Xhr.responsetext property gets the string value "{' Name ': ' Tim ', ' sex ': ' Male '}, again emphasizing that this is a string
3. String conversion to JSON
The string is converted to JSON, using the parse function of json, Json_data = Json.parse (Xhr.responsetext), and then in the JavaScript code, you can directly access the Name property, Json_ Data.name, Json_data.sex.
4. Check that the dictionary is empty
JavaScript dictionary type, in fact, can be considered a JSON data, when the future check the dictionary is empty, can not call the length property of the way to determine the size of zero, one way is to traverse the dictionary property, get to the value, then set a flag bit traversal to true, otherwise false, Another method is to convert the variable through json.stringify (Json_data) to a string, and then compare it with the ' {} ' string, or null if it is equal, not equal to NULL.
[Timlinux] JavaScript Ajax received data converted to JSON format