Ajax gets data from the server---the original eco-Ajax

Source: Internet
Author: User

write it in front.

The data that Ajax obtains from the server is a string, but with different parsing, it can be parsed into XML or JSON for application.

Generally speaking. Data in XML format is more common, but the server and client are more complex to parse, while using JSON statements, the service side needs to do more work, but to the client, by using the Eval () function to parse, you will get the JS object, It is very convenient to use. In the course of use, which method to use, according to the actual needs of the project, it is recommended: In the case of using JSON, try to use JSON.

See examples for specific usage.

Example

1.XML Data User.xml

<?xml version= "1.0" encoding= "Utf-8"?><users>  <user>    <username> Zhang San xml</ username>    <age>33</age>  </user>  <user>    <username> John Doe xml</ username>    <age>34</age>  </user></users>

2.JSON Data User.js

[    {username: "Zhang San json", age:33},    {username: "John Doe JSON", age:34}]

3.HTML page Code

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
 
Effect

Run the page and click the "Load XML data" button to read the data from the XML data file and add it to the table; Click the "Load JSON data" button to read the data from the JS file and add it to the table.

Ajax gets data from the server---the original eco-Ajax

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.