运行 数据改变时函数
Run function if data changed
我是 jQuery 的新手,不知道如何成功 运行 我在页面中使用的脚本。问题是只有当我的 load.php 文件发生变化时我才需要淡入和淡出文本,但不像现在这样经常发生变化,请帮助任何人......非常感谢!
这是我的代码:
$(document).ready( function(){
$('#auto').load('load.php');
refresh();
});
function refresh()
{
setTimeout(function() {
$('#auto').fadeOut('fast').load('load.php').fadeIn('fast');
refresh();
}, 2000);
}
试试这个:
function refresh()
{
setTimeout(function() {
$.get('load.php', function(data) {
if (data !== $('#auto').html()) {
$('#auto').fadeOut('fast').html(data).fadeIn('fast');
}
refresh();
});
}, 2000);
}
这使得请求在 load()
之外,并且只会淡化 in/out + 如果内容不同则替换内容。
我是 jQuery 的新手,不知道如何成功 运行 我在页面中使用的脚本。问题是只有当我的 load.php 文件发生变化时我才需要淡入和淡出文本,但不像现在这样经常发生变化,请帮助任何人......非常感谢!
这是我的代码:
$(document).ready( function(){
$('#auto').load('load.php');
refresh();
});
function refresh()
{
setTimeout(function() {
$('#auto').fadeOut('fast').load('load.php').fadeIn('fast');
refresh();
}, 2000);
}
试试这个:
function refresh()
{
setTimeout(function() {
$.get('load.php', function(data) {
if (data !== $('#auto').html()) {
$('#auto').fadeOut('fast').html(data).fadeIn('fast');
}
refresh();
});
}, 2000);
}
这使得请求在 load()
之外,并且只会淡化 in/out + 如果内容不同则替换内容。