On the data processing problem after the AJAX operation database

Source: Internet
Author: User
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

  • 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.