Use native ajax to process json strings, ajaxjson string
AJAX
AJAX = Asynchronous JavaScript and XML (Asynchronous JavaScript and XML ).
AJAX is not a new programming language, but a new method that uses existing standards.
AJAX is the art of exchanging data with the server and updating some webpages without reloading the entire page.
What is json?
The full name of JSON is Javascript Object Notation (javascript Object Notation), which is based on the javascript Object literal, the data in JSON is saved in curly braces -- {}. JSON is a data exchange format if further analysis is performed on the purpose. JSON is arranged in the format of name: value. The following json1 is a json object.
Var json1 = {"name": "Li Ming", "age": 21, "sex": "boy "}
What is a json string?
Double quotation marks (or single quotation marks) are added to both sides of json. To avoid conflicts with the internal double quotation marks, we put single quotation marks on the outside to form a json string, as shown in json2 below.
Var json2 = '{"name": "Li Ming", "age": 21, "sex": "boy "}'
2. On our data provision page, output our json. We still call the data provision page tigong. php
The Code is as follows:
<? Phpheader ("content-type: text/html; charset = UTF-8"); echo '{"name": "Dawn", "age": "12", "sex ": "male"} ';?>
3. receive data on our front-end page, parse the json string into a json object using the eval method, and traverse it using the for loop. We call this page testjsonevel.html
<! DOCTYPE html>
Evel has no compatibility issues, but security vulnerabilities.
Effect
4.use json.parse to name a json string as a jsonobject. We call this page testjsonparse.html. The Code is as follows:
<! DOCTYPE html>
JSON. parse does not have a security vulnerability, but it has compatibility. IE8 and below are not supported.
Effect
The above section describes how to use native ajax to process json strings. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!