jQuery,加载前比较内容 [英] jQuery, compare content before loading
本文介绍了jQuery,加载前比较内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果旧内容和新内容不相同,我将如何去更新divs内容。只有在相同时才更新。如在,让我们说。目前我有这个:
< div style =min-height:200px; max-height:220px; height:auto ;溢出-γ:汽车;填充:2px的;类= 主要 >
<?php include(ajax / display_messages.php);?>
< / div>
$ b $(setInterval(function(){
'('。main')。load('ajax / display_messages.php',
函数(response,status,xhr){});
},2000));
有没有办法让它先检查内容?在更新之前?使用 rel =nofollow> $。get()
而不是 .load()
。
var $ main = $('。main');
$ .get('ajax / display_messages.php',function(data)
{
if($ main.html()!== data)$ main.html(data);
});
How would I go around updating a divs content, if the old content and the new content aren't the same. Only update if it's the same. As in, let's say. Currently I have this:
<div style="min-height:200px;max-height:220px;height:auto;overflow-y:auto;padding:2px;" class="main">
<?php include("ajax/display_messages.php");?>
</div>
$(setInterval(function() {
$('.main').load('ajax/display_messages.php',
function(response, status, xhr){ });
}, 2000));
Is there any way to make it check the contents first? Before updating it?
解决方案
Use $.get()
instead of .load()
.
var $main = $('.main');
$.get('ajax/display_messages.php', function (data)
{
if ($main.html() !== data) $main.html(data);
});
这篇关于jQuery,加载前比较内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文