tags:

views:

38

answers:

2

I'm trying to refresh my recent list every 5 seconds. I was looking at ajax and found jquery.

I found a function known as "everyTime"

This is what I have so far, I don't really know how to get it to work... It's not working:\

<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
<script>
$(document).everyTime(5s, function(i) {
  <?php include "recent.php";?>
}, 0);
</script>
</head>
<body>
<div id="testDiv">
<h2>This is default. Waiting for refresh</h2>
</div>
</body>
+4  A: 

everyTime seems to be a jQuery plugin that has a lot of functionality you're not using here. For what you're doing, you can just use setInterval thus:

setInterval(function() {
    // refresh list
}, 5000)

where the second parameter is the number of milliseconds.

Note on everyTime

If really you want to use everyTime, you'll need to make your first parameter a string, that is:

$(document).everyTime("5s", function(i) { }, 0);

Note the quotes around the 5s. You'll also need to include the appropriate javascript file for the plugin (not just for jQuery) at the top, i.e.

<script type="text/javascript" src="/js/jquery.timers.js"></script> 
wxs
Thanks a lot this worked for me. :) I decided to use setInterval, which works splendid!
Kyle
A: 

5s is neither an integer or a string, and so it's an invalid input. To achieve the desired behavior you can use an integer number of microseconds:

$(document).everyTime(5000, function(i) {
  <?php include "recent.php";?>
}, 0);

or a string indicating the interval:

$(document).everyTime('5s', function(i) {
  <?php include "recent.php";?>
}, 0);

(here's a reference)

Mark E