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 ~