Use jquery and json to obtain the dataset code from the background _ jquery

Source: Internet
Author: User
Recently, I am using ajax to create a website without any concerns. I found that the data is transmitted well, but I don't know how to obtain the data set. So I checked some information on the Internet to transfer the data. Now I want to share it with you, if you do not know, you can study with me. If you know, please give me some advice. The method I chose is to use json to obtain the dataset. In fact, Json is a data format. In the background, convert the data to a format, and then parse the data in the foreground using the same method, similar to serialization. Json format is mainly composed of key-value pairs, which can represent multiple data. For example

{Name: zhangsan, age: 12, class: 1}

Json can also represent a dataset consisting of {} And. For example, we need to query a table from the database and transmit the table to the foreground. However, dataset cannot be directly transmitted. We need to convert dataset data to json data, this allows the front-end js to parse data. Next I will write the conversion format.

{Name: Table Name, Rows: [{SName: Name, SAge: Age} {...}]} This is the data format of a table,

{Tables: [{Name: Table 1 Name, Rows: [{SName: Name, SAge: Age }{...} {...}]} {Name: Table 2 Name, Rows: [{SName: Name, SAge: Age }{...} {...}]} this is the data format of multiple tables.

The following example shows how to transmit a dataset.

First, we need a front-end page to obtain the data studentinfo.html. on this page, we have a function to obtain the data in Json format. jquery encapsulates such a function, JSON. parse ();

The Code is as follows:


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.