Other data types are not a problem when using JSON to pass data in Ajax, but if the server-side generated JSON has data of type bool, there is a small problem when parsing the client, summarized as follows:
The JSON returned by the server is:
Copy Code code as follows:
{"typeID": [1037], "Title": "Hebei software vocational and Technical College", "Intro": "", "Islink": "false", "Linkurl": "http://www.hbsi.edu.cn", "Ispic": " True "," Picture ":"/newsimages/hbsi.jpg "," Content ":" <p><br></p> "}
Where properties: Islink and Ispic are all bool types, use the method on the client:
Copy Code code as follows:
document.getElementById ("CheckBox1"). Checked = news. Islink;
The check box is selected, but Islink is false and should not be selected.
For the reason, JavaScript has three basic types of data (string string, numeric number, Boolean Boolean), two reference data types (object, array array), and two special data types (Null, Undefined). Other types of conversions to the bool type have the following principles:
Values converted to bool by data type
Null FALSE
Undefined FALSE
Object TRUE
function TRUE
0 FALSE
1 TRUE
Numbers from 0, 1 TRUE
String TRUE
"" (empty string) FALSE
At this point, Islink is the string "false" in JSON, so the bool type is true after the conversion.
Treatment methods:
Copy Code code as follows:
document.getElementById ("CheckBox1"). Checked = news. islink== "true";