Updating a table of data with ajax/JQuery

Glow

I am trying to update a table using data from ajax/json.

Here is JQuery Code: Updated to use functions for simpler execution.

$(document).ready(function() {
    //var userid = $( ".migrating" ).data( "userid" );

    function ajaxUpdate(userid){
        window.setInterval(function(){
         $.ajax({
                url: "info.php?userid=" + userid + "",
                async: true,
                type: "POST",
                data: "{}",

                contentType: "application/json; charset=utf-8",
                dataType: "json",

                success: function(results) {
                     $("#uid" + userid).html(results.uid);
                     $("#moved" + userid).html(results.moved);
                     $("#percentmoved" + userid).html(results.percentmoved);
                     $("#avgspeed" + userid).html(results.avgspeed);
                     $("#eta" + userid).html(results.eta);
                }
            });
        }, 3000); 
    }

    ajaxUpdate($(".migrating").data("userid"));

});

HTML Code:

<table>
    <tr>
        <td><b>ID</b></td>
        <td><b>Moved</b></td>
        <td><b>Moved %</b></td>
        <td><b>Avg Speed</b></td>
        <td><b>ETA</b></td>
    </tr>

    <tr class="migrating" data-userid="101">
        <td><div id="uid101">Loading...</div></td>
        <td><div id="moved101">Loading...</div></td>
        <td><div id="percentmoved101">Loading...</div></td>
        <td><div id="avgspeed101">Loading...</div></td>
        <td><div id="eta101">Loading...</div></td>
    </tr>

    <tr class="migrating" data-userid="102">
        <td><div id="uid102">Loading...</div></td>
        <td><div id="moved102">Loading...</div></td>
        <td><div id="percentmoved102">Loading...</div></td>
        <td><div id="avgspeed102">Loading...</div></td>
        <td><div id="eta102">Loading...</div></td>
    </tr>

</table>

i want to issue "ajaxUpdate()" on each instance of class="migrating" from the tables.

My info.php file simply outputs random strings and the the userid from the post string, the only problem is i need todo this for each of the fields.

I'm assuming the cause of the problem is having multiple class="migration" fields.

I've tried searching but couldn't find anything specific to multiple rows.

Muhammad Reda

You can user jQuery.each to loop through the results. Something similar to this:

success: function(results) {
   $.each(results, function(index) {
       // your logic goes here.
   })
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

updating data in external table

From Dev

Updating data from the table

From Dev

Comparing data and updating table

From Dev

Updating table data in Oracle

From Dev

Updating table data in optimal manner

From Dev

Display data in a table for updating purposes

From Java

Timestamps are not updating while attaching data in pivot table

From Dev

Updating Variable using functions in data.table?

From Dev

Updating entity data to Azure storage table

From Dev

Updating table data in rails using ajax

From Dev

Updating Data in Table from AJAX Call

From Dev

Save() is not updating data in table in datamapper with codeigniter

From Dev

PHP - Updating / Editing Data / Records In The Database Table

From Dev

R: Updating NAs in a data table with values of another data table

From Dev

R: Updating NAs in a data table with values of another data table

From Dev

Is there any way to update PrimeFaces data table without updating the table headers?

From Dev

Updating second table based on first table data in rails

From Dev

Updating a list of models with a list of data in data.table

From Dev

Updating a table using SQL function (data dependent on source) in the INNER JOIN

From Dev

D3: value in data object changed but not updating in table

From Dev

System.Data.SqlClient.SqlException occurs for updating table

From Dev

Need help on updating a data on a database table using facebox

From Dev

data missing only in a single column after updating mysql table

From Dev

How to disable updating and saving data in the table through model in Rails?

From Dev

data.table behaviour with row.names and updating

From Dev

Data flow task not updating SQL Server table from oracle db

From Dev

SQL server : Inserting/updating missing data from one table to another

From Dev

Updating MySQL table rows based on data in another column

From Dev

updating "multiple" columns of "selected" rows of a data table with duplicate key values

Related Related

  1. 1

    updating data in external table

  2. 2

    Updating data from the table

  3. 3

    Comparing data and updating table

  4. 4

    Updating table data in Oracle

  5. 5

    Updating table data in optimal manner

  6. 6

    Display data in a table for updating purposes

  7. 7

    Timestamps are not updating while attaching data in pivot table

  8. 8

    Updating Variable using functions in data.table?

  9. 9

    Updating entity data to Azure storage table

  10. 10

    Updating table data in rails using ajax

  11. 11

    Updating Data in Table from AJAX Call

  12. 12

    Save() is not updating data in table in datamapper with codeigniter

  13. 13

    PHP - Updating / Editing Data / Records In The Database Table

  14. 14

    R: Updating NAs in a data table with values of another data table

  15. 15

    R: Updating NAs in a data table with values of another data table

  16. 16

    Is there any way to update PrimeFaces data table without updating the table headers?

  17. 17

    Updating second table based on first table data in rails

  18. 18

    Updating a list of models with a list of data in data.table

  19. 19

    Updating a table using SQL function (data dependent on source) in the INNER JOIN

  20. 20

    D3: value in data object changed but not updating in table

  21. 21

    System.Data.SqlClient.SqlException occurs for updating table

  22. 22

    Need help on updating a data on a database table using facebox

  23. 23

    data missing only in a single column after updating mysql table

  24. 24

    How to disable updating and saving data in the table through model in Rails?

  25. 25

    data.table behaviour with row.names and updating

  26. 26

    Data flow task not updating SQL Server table from oracle db

  27. 27

    SQL server : Inserting/updating missing data from one table to another

  28. 28

    Updating MySQL table rows based on data in another column

  29. 29

    updating "multiple" columns of "selected" rows of a data table with duplicate key values

HotTag

Archive