When you do a page, similar to the micro-blog to pull to the bottom can choose "load more", now through the AJAX implementation of the database operation
function Ajax () {var Page=document.getelementbyid ("Pagenum"). value++; First declare an asynchronous request object var xmlhttpreg = null; if (window. ActiveXObject) {//if IE Xmlhttpreg = new ActiveXObject ("Microsoft.XMLHTTP"); } else if (window. XMLHttpRequest) {Xmlhttpreg = new XMLHttpRequest ();//Instantiate a Xmlhttpreg}//If the instantiation succeeds, call open ( ) method, start preparing to send the request to the server if (Xmlhttpreg! = null) {Xmlhttpreg.open ("get", "pro.php?index=" +page, true); Xmlhttpreg.send (NULL); Xmlhttpreg.onreadystatechange = Doresult; Set callback Function}//callback function//Once the value of readyState is changed, this function will be called, readystate=4 means complete the corresponding//Set function Doresult () function Doresult () {if (xmlhttpreg.readystate = = 4) {//4 represents execution completion if (Xmlhttpreg.status = = 200) {//200 represents execution success//assigns the value of Xmlhttpreg.responsetext to ID Res The text element document.getElementById ("ResText"). InnerHTML = Xmlhttpreg.responsetext; } } } }
The background database is implemented in PHP, and the statement is
... $sql = "SELECT * from Tb_test limit". $index, $result = mysql_query ($sql, $con);
I don't know what to do here.
Usually
Use while ($row =mysql_fetch_array ($result)) {
......
}
Yes, now I don't know how to output, and my foreground page, these updated data is in a table
Reply to discussion (solution)
while ($row =mysql_fetch_array ($result)) {
......
}
The same in this loop, but at this point can be added TR and other table under the label and then combined into an array, and then converted to the output format you want to output to the results can be.
Data to be retrieved from the database (typically an array), Echo Json_encode ($res);
JS for the front desk
var Res=xmlhttpreg.responsetext;
Res=eval (' (' +res+ ') ');
Solve it
res[' key Name '], you can get the corresponding key value
Data to be retrieved from the database (typically an array), Echo Json_encode ($res);
JS for the front desk
var Res=xmlhttpreg.responsetext;
Res=eval (' (' +res+ ') ');
Solve it
res[' key Name '], you can get the corresponding key value
And then output those tables in JS?
You can say, like the 1 floor, in PHP to organize a good table (is a string), and then directly echo,js get it without solution, directly into the location to be displayed
Because I think the JS Loop Data organization HTML is more troublesome (in general), it is not as good as the direct output of PHP organization