Use native ajax to process json strings, ajaxjson string

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.