Question: I'm new to jquery/ajax. I'm trying to refresh a div every x seconds

**Code:**

```
<div id="page-wrapper">

<div id = "x"></div>
<div id = "y"></div>
<div id = "z"></div>

</div>

```

I have to refresh div with id 'page-wrapper' every x seconds. while refreshing I need to have a callback function in which I'll update data in divs (x,y,z).

Answer: 
Use `setInterval` to run a function every n milliseconds. In that function you can retrieve data via an ajax call or other method and update the data in your divs.

For example:

```
var intervalInMs = 5000;
setInterval(function(){
 $.ajax({url: "data.json", success: function(result){
        $("#x").text(result.x);
        $("#y").text(result.y);
        $("#z").text(result.z);
    }});
},intervalInMs);

```
You can code something like this -
(You can change interval value which I set to 1000ms.

```
var interval = setInterval(function() {

$.get("YOUR DATA SOURCE", function(data, status){
    //Update DIV values using data
});

},1000);

```