When we use Ajax, the most important thing is the dynamic generation of pages in the success function. The current scenario is to use ajax to dynamically generate tables or other list formats for query output. I checked some information on the Internet. Most examples of dynamic table generation are implemented by spelling HTML text. This disadvantage is that JS performance is not high if the data volume is large. After referring to some materials, I decided to use dynamic HTML elements for display. The core function is document. createelement (string tagname) to generate elements such as table, thead, tbody, TR, th, and TD. The Code is as follows:
<HTML>
<Head>
<Title> Create Table </title>
</Head>
<Body>
<Div id = "Container"> </div>
<SCRIPT type = "text/JavaScript">
VaR con = Document. getelementbyid ("Container ");
VaR table = Document. createelement ("table ");
VaR thead = table. createthead ();
VaR tbody = table. createtbody ();
VaR TR = Document. createelement ("TR ");
For (VAR I = 0; I <5; I ++ ){
Th = Document. createelement ("th ");
Th. innerhtml = "title" + I;
Tr. appendchild (th );
}
Thead. appendchild (TR );
For (VAR I = 0; I <10; I ++ ){
VaR TR = Document. createelement ("TR ");
For (var j = 0; j <5; j ++ ){
TD = Document. createelement ("TD ");
TD. innerhtml = I + "," + J;
Tr. appendchild (TD );
}
Tbody. appendchild (TR );
}
Con. appendchild (table );
</SCRIPT>
</Body>
</Html>
If you want to improve the performance of your applications, you can also point it out or use more efficient methods.
Using the createelement function to dynamically create a table