3

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"></script>
<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>
Gabriel Llamas
  • 18,244
  • 26
  • 87
  • 112
Kyle
  • 3,004
  • 15
  • 52
  • 79
  • Have you tried using `setInterval` (http://www.w3schools.com/js/js_timing.asp)? And using php include won't work the way you want - you might consider using `load()` (http://api.jquery.com/load/) – Mottie Oct 05 '10 at 01:47
  • Thanks a lot, you are right php include didn't work. I used as you referenced me to; $('#result').load('recent.php'); Thank you:) – Kyle Oct 05 '10 at 02:06
  • It's not working because `5s` I mean seriously, it's neither a number or a string. – Derek 朕會功夫 Jun 03 '14 at 20:24

3 Answers3

15

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 you really 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
  • 5,617
  • 5
  • 36
  • 51
2

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 milliseconds:

$(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 Elliot
  • 75,278
  • 22
  • 140
  • 160
0

You can use everyTime plugin with jQuery Ajax like this:

var j = jQuery.noConflict();
j(document).ready(function()
{
    j(".refresh").everyTime(1000,function(i){
        j.ajax({
          url: "refresh.php",
          cache: false,
          success: function(html){
            j(".refresh").html(html);
          }
        })
    })

});

Late answer. Hope this will help users researching on similar functions.

Abhijith Sasikumar
  • 13,262
  • 4
  • 31
  • 45