How can I update a div continuously

I have an asp.net application where I have a div that shows the value from another site. The value of this site is constantly changing.

I want my div to automatically update after a while.

How can i do this.

+3
source share
4 answers
$(document).ready(function() {
        var refreshId = setInterval(function()
        {
             $('#main').fadeOut("slow").load('Default.aspx').fadeIn("slow");
        }, 50000);
        });
+5
source

Sorry for the mistake. setTimeout is used instead of setInterval to accommodate any delay that may occur in an AJAX request.

var to;
$(function() {
    // initialize timer to update div every 5 seconds
    to = setTimeout(updateDivContent, 5000);
});

function updateDivContent() {
    // make your AJAX/LOAD request for the data here to populate div
    $('#mydivcontainer').empty().load('myAspFileToGrabExternalData.aspx', null, function() {
        // reset the timer to grab the content in another 5 seconds
        to = setTimeout(updateDivContent, 5000);
    });
}

You can read the jQuery download method here .

+4
source

setinterval jquery/javascript. : http://docs.jquery.com/Tutorials:Scroll_Up_Headline_Reader jquery .

+1

( ), ( , , ), . , setInterval() , , (.. 5 , 6 , 1 , ).

cballou :

var to;
$(function() {
    // initialize timer to update div every 5 seconds
    to = setTimeout(updateDivContent, 5000);
});

function updateDivContent() {
    // make your AJAX/LOAD request for the data here to populate div
    $('#mydivcontainer').load('myAspFileToGrabExternalData.aspx', null, function() {
        // reset the timer to grab the content in another 5 seconds
        to = setTimeout(updateDivContent, 5000);
    });
}

, cballou , , , ( 3 5 , 10 ..).

+1
source

Source: https://habr.com/ru/post/1722437/


All Articles