1

I'm new to Javascript and AJAX so please excuse my newb question. I have an AJAX call (that is working) and I'd like to have it refresh the contents of a div every 5 minutes (I'm not using jquery). This is how I'm calling the AJAX function in the <head></head> of my html page:

    <script type=text/javascript>
        setInterval(ajaxCall(), 300000);
    </script>

The initial page load populates the div, but the content of the div doesn't refresh after 5 minutes. What am I doing wrong?

  • Call your div id. Or take a look here : http://stackoverflow.com/questions/25446628/ajax-jquery-refresh-div-every-5-seconds – DesignStudios May 25 '15 at 17:03

3 Answers3

5

Change your code to this:

setInterval(ajaxCall, 300000);

To pass an argument:

setInterval(function(){ ajaxCall(someCoolValue); }, 300000);

Notice the lack of parentheses in ajaxCall. You want to pass the function itself, not call the function. More examples on MDN.

Andy Gaskell
  • 31,495
  • 6
  • 74
  • 83
1

You need to wrap your ajaxCall.

<script type=text/javascript>
    setInterval(function(){ ajaxCall(); }, 300000);
</script>
Zee
  • 8,420
  • 5
  • 36
  • 58
0

Here

<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
</head>

<div id="links">

</div>

<script language="javascript" type="text/javascript">
var timeout = setTimeout(reloadChat, 300000);

function reloadChat () {
$('#links').load('test.php #links',function () {
        $(this).unwrap();
        timeout = setTimeout(reloadChat, 300000);
});
}
</script>

Also you are calling it wrong correct syntax would be ,

setInterval(ajaxCall, 300000);

Hope it helps :D

Adarsh Vardhan
  • 257
  • 3
  • 13