Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6873383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:03:42+00:00 2026-05-27T04:03:42+00:00

$(document).ready(function(){ setInterval(function(){ $.ajax({ url: getLiveData.php, success: function(result){ $.each(result, function(i, result){ var t = $(table#insideTable);

  • 0
$(document).ready(function(){
      setInterval(function(){
         $.ajax({ url: "getLiveData.php",
             success: function(result){
                 $.each(result, function(i, result){
                    var t = $("table#insideTable");
                    t.append('<tr><td>' + result.carNo + '</td><td>' +
                             result.carSpeed + '</td></tr>');
                    });
             }, 
             dataType: "json"
          });
      }, 600000);
});

Hello, I was trying to use the code above to update car speeds for every 10 mins.

–data at 10:20AM—–

+-------+-------+
|car    |speed  |
+-------+-------+
|1      |170 kph|
+-------+-------+
|2      |150 kph|
+-------+-------+
|3      |190 kph|
+-------+-------+

–data at 10:30AM—–

+-------+-------+
|car    |speed  |
+-------+-------+
|1      |180 kph|
+-------+-------+
|2      |155 kph|
+-------+-------+
|3      |174 kph|
+-------+-------+

However, after running the code, the results obtained from the two time points are all shown, with one after the other (See below).

+-------+-------+
|car    |speed  |
+-------+-------+
|1      |170 kph|
+-------+-------+
|2      |150 kph|
+-------+-------+
|3      |190 kph|
+-------+-------+
|1      |180 kph|
+-------+-------+
|2      |155 kph|
+-------+-------+
|3      |174 kph|
+-------+-------+

What I really want is to have the new data from a later time to replace the current one.

+-------+-------+
|car    |speed  |
+-------+-------+
|1      |180 kph|
+-------+-------+
|2      |155 kph|
+-------+-------+
|3      |174 kph|
+-------+-------+

Can anyone help me?

Many thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:03:42+00:00Added an answer on May 27, 2026 at 4:03 am

    You want to use the .html() function in place of .append():

    Change:

    success: function(result){
        $.each(result, function(i, result){
            var t = $("table#insideTable");
            t.append('<tr><td>' + result.carNo + '</td><td>' + result.carSpeed + '</td></tr>');
        });
    }
    

    To:

    success: function(result){
    
        //create an output variable that will be added to the DOM when we're finished
        var output = '';
    
        //iterate through the results of the AJAX request
        $.each(result, function(i, result){
    
            //add a row to the output variable
            output += '<tr><td>' + result.carNo + '</td><td>' + result.carSpeed + '</td></tr>';
        });
    
        //add the output to the DOM, notice that since we are only adding nodes to the DOM once this creates less CPU overhead than appending each row separately (we also save overhead by not selecting the table element during each iteration of the $.each() loop)
        $("#insideTable").html(output);
    }
    

    Which will replace the HTML inside the table element rather than append to it. Here is a demonstration of using .html() versus .append(): http://jsfiddle.net/jasper/TKaVF/

    Here is the documentation for .html(): http://api.jquery.com/html

    On a side-note, it doesn’t make your selector any faster by adding table since you are looking-up an ID (which is quite fast on its own).

    var t = $("table#insideTable");
    

    Would be faster as:

    var t = $("#insideTable");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$(document).ready(function() { $('#content').html(''); $.ajax({ url:'data.json', dataType: json, success: function(data) { $('#content').append('<p>'+data.rank+'</p>'); } });}); In
$(document).ready(function(){ var refreshId = setInterval(function() { periodicRefresh(); }, 9000); }) . function periodicRefresh() {
I have a ajax function as below <script type=text/javascript> $(document).ready(function () { var timer,
I have a jquery ex like this.. jQuery(document).ready(function() { var refreshId = setInterval(function() {
$(document).ready(function() { function countChecked() { var n = $(input:checked).length; $(div).text(n + (n <= 1
$(document).ready(function() { $('#username').focus(function() { $(this).val(''); }) $('#username').blur(function() { var l = $(this).val.length; if (l
$(document).ready(function() { //Check City Value var city_value = parseInt($(#city).val()); if( city_value == 0) {
$(document).ready(function(){ contM = $('#main-content'); contS = $('#second-content'); $(contM).hide(); $(contS).hide(); function loadURL(url) { console.log(loadURL: +
Currently im polling/checking every 1000ms by doing a GET to /moves: jQuery(document).ready(function() { setInterval(function()
In my code, I have: $(document).ready(function() { $.ajaxSetup ({ // Disable caching of AJAX

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.