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: