Methods for processing JSON strings using native AJAX _ajax related

Source: Internet
Author: User
Tags eval ming

Ajax

AJAX = Asynchronous JavaScript and XML (asynchronous JavaScript and XML).

AJAX is not a new programming language, but a new way of using existing standards.

AJAX is the art of exchanging data with the server and updating parts of the Web page without reloading the entire page.

What is JSON?

The full name of JSON is the JavaScript Object notation (JavaScript objects notation), which is based on the literal amount of JavaScript objects, and if you look at it from the eye, the data in JSON is stored in curly braces--{}, If further analysis is used, JSON is a data interchange format. Within JSON, the format is arranged by name: value, such as the following Json1, which is a JSON object.

var json1={"name": "Li Ming", "Age": "Sex": "Boy"}

What is a JSON string?

To put double quotes (or single quotes) on both sides of the JSON, in order to avoid conflicting with the inner double quotes, we place a single quotation mark over the outside, which is a JSON string, as in the following Json2

var json2= ' {' name ': "Li Ming", "Age": "Sex": "Boy"} '

2. In our data supply page, output our JSON, we still put the data to provide the page called tigong.php

The code is as follows:

<?php
Header ("Content-type:text/html;charset=utf-8");
Echo ' {' name ': "Dawn", "Age": "A", "Sex": "Male"} ';
? >

3. Receive data on our front-end page and use the Eval method to parse the JSON string into a JSON object and iterate it out with a for loop. We call this page a testjsonevel.html.

<! DOCTYPE html>  

Evel there are no compatibility issues, but there are security vulnerabilities.

Effect as shown:

4. Using the Json.parse method to parse the JSON string as a JSON object, we call this page testjsonparse.html, which is as follows

<! DOCTYPE html>  

Json.parse There are no security vulnerabilities, but there are compatibility, IE8, and the following are not supported.

Effect as shown

The above is a small set to introduce the use of native AJAX processing JSON string method, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.