How to refresh / reload content to a div using jQuery


With JQuery ( light weight, super Java Script library) we can make call to API for fetching data or loading web page.

How about refresh or reload contents every 5 second ?

Steps

To auto reload the content we need the following

  • Create function
  • Set interval

Function

$(function () {
  // Function load content
function fetchData(){

}

});

Turn the data fetching portion of the AJAX call into JavaScript function inside the document ready jQuery function.

Set interval

setInterval(function(){
     fetchData()
 },5000)

The setInterval will invoke the function every 5 second using the call back function.

Published by

Manoj

A developer,teacher and a blogger obsessed with Python,Dart and open source world from India

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.