JQuery - Update Table

I am trying to reload a table that was also generated by PHP.

The table has an identifier: #bookmarks

After the user clicks the button, the table should reload the content + data they just added. I am a little confused because I don’t know how to send all data from PHP result.

0


a source to share


6 answers


For specific help with jQuery, check out the jEditable plugin , which is designed to provide in-place editing of data. There are also instructions on how to collect data and store it.



0


a source


This assumes that your PHP is returning inline-ready HTML for the table:

$("#update_button").click(function(){
    $("#mytable").load("/tools/getTable.php")
})

      

on your page you need a DIV placeholder:



<div id="mytable"></div>

      

and your getTable.php should echo the html back like this:

<table>
  <tr>
    <td>col1<td>
    <td>col2<td>
  <tr>
</table>

      

+4


a source


As a point:

  • Send user data to PHP page via AJAX request. (Look at the jQuery Form plugin)
  • A PHP page should accept and validate data, insert it into the database, and then send a response to the page in some format (I recommend JSON using the php json_encode .
    • The response should be either "rejected" or "accepted" with the user data returned, cleaned to suit the requirements of your own system.
  • Then, in the AJAX success callback method, use jQuery to add the data to the table, or give them a message telling them why it was rejected.
+1


a source


When the user clicks the button, you must invoke the code that was used to load the table. Data can be data from the beginning + data added by users. Or the data can be reassigned from the server, depending on how your application works.

A little more information may clarify the situation, so we could provide more specific answers.

0


a source


Well, the table is created using this:

<table id="bookmarks">
        <thead>
            <tr class="table-top">
                <th>Thumbnail</th>
                <th>Title/Description</th>
                <th>Tags</th>
                <th>Action</th>
            </tr>
        </thead>
        <?php
        $hID = userToID($_SESSION['username']);
        $hQuery = mysql_query("SELECT * FROM linkz WHERE userid='$hID'") or die(mysql_error());
        while($hRow = mysql_fetch_array($hQuery)) {
            echo "<tr class='link'><td><img src='http://www.thumbshots.de/cgi-bin/show.cgi?url=".$hRow["location"]."' /></td><td><a href='share/".$hRow['shareid']."'>".$hRow["title"]."</a> - <i>". $hRow["description"]."</i><br /><b>Share Link:</b> http://www.linkbase.us/share/".$hRow['shareid']."</td><td>".$hRow['tags']."</td><td><a href='#' id='".$hRow['shareid']."' class='delbutton'>Delete</a></td></tr>";
        }
    ?>
    </table>

      

0


a source


First, you need to learn the basics of AJAX first.

You need to learn to walk before you can start working.

Finding some tutorials on Ajax, PHP and Ajax

Here and here start 2 s

0


a source







All Articles