Jquery Dom operations, JSON Data Format

Source: Internet
Author: User
Code
<? PHP
If (isset ($ _ post ['action']) & $ _ post ['action'] = 'getdata '){
$ Mydata = array ();
For ($ tmpcount = 0; $ tmpcount <10; $ tmpcount ++ ){
$ Mydata [] = array ('d1 '=> rand (), 'd2' => rand (), 'd3 '=> rand ));
}
Require_once ('lib/JSON. php ');
$ Myjson = new services_json ();
$ Jsonvalue = $ myjson-> encode ($ mydata );
Echo $ jsonvalue;
Exit ();
}
?>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> data loading </title>
<Script language = "JavaScript" type = "text/JavaScript" src = "JS/jquery-1.2.6.min.js"> <SCRIPT>
<Script language = "JavaScript">
Function createtabledata (){
$. Ajax ({
Type: "Post ",
URL: "jquerydom. php ",
Data: {Action: 'getdata '},
Error: function (){
Alert ('data retrieval failed ');
},
Success: function (data, textstatus ){
VaR returndata = eval ('+ Data + ')');
VaR datacontent = $ ("# datacontent tbody ");
Datacontent.html ('');
VaR tr_dom =$ ('<tr> </tr> ');
VaR td_dom =$ ('<TD> </TD> ');
VaR datalength = returndata. length;
For (VAR I = 0; I <datalength; I ++ ){
VaR tmptr = tr_dom.clone ();
Td_dom.clone().html (returndata [I]. d1.tostring (). appendto (tmptr );
Td_dom.clone().html (returndata [I]. d2.tostring (). appendto (tmptr );
Td_dom.clone().html (returndata [I]. d3.tostring (). appendto (tmptr );
Tmptr. appendto (datacontent );
}
}
});
}
</SCRIPT>
</Head>
<Body>
<Input type = "button" onclick = "createtabledata ();" value = "Get Data"/>
<Table id = "datacontent" style = "border: 1px solid" mce_style = "border: 1px solid">
<Thead>
<Tr> <TH> Field 1 </Th> <TH> Field 2 </Th> <TH> Field 3 </Th> </tr>
</Thead>
<Tbody>
</Tbody>
</Table>
</Body>
</Html>

 

 

A json. php class is referenced to generate JSON data. php Versions later than php5.2 ~ It seems that it already comes ~ JSON Function ~

Jquery. Ajax functions are called to submit data ~

 

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.