Markcce Eros Markcce Eros - 1 month ago 11
Javascript Question

jQuery GET inject code into div and refresh

I am getting the source code from a local file using jQuery GET and injecting the code into a

div
.

My problem is that this code is not refreshing.

jQuery

jQuery.get("some_local_file_url_here", function( the_page_source ) {

jQuery("#target_div").html(the_page_source);

});


HTML

<div id="target_div"> the_page_source goes here </div>


How can I get it to work as it I did a reload to the page?

Answer
window.setInterval(function(){
    jQuery.get("some_local_file_url_here", function( the_page_source ) {

        jQuery("#target_div").html(the_page_source);

    });
}, 3000);

The setInterval() method calls a function or evaluates an expression at specified intervals (in milliseconds).

TIPS:

3000 = every 3 seconds

1000 = 1 second

You can change it.

read more: Window setInterval() Method