可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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:\
This is default. Waiting for refresh
回答1:
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.
回答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) { }, 0);
or a string indicating the interval:
$(document).everyTime('5s', function(i) { }, 0);
(here's a reference)
回答3:
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.