jQuery.ajax()
. 请看这里的
jQuery API Documentation
如果你想为自己的生活找到一个替代方案,那么这个答案就是为你准备的
meta
标签
你可以获取更新网站的内容,搜索特定的
div
或者类似的东西,然后检查是否有新条目。
能够
去做吧!
setInterval(function(){
}, 15000); // The loop function will check every 15 seconds
ajax()
呼叫
$.ajax({
url: 'YOUR URL HERE',
type: 'GET',
success: function(data) {
var check = $(data).find('#chat');
// Here you get the `div` -> `#chat`
// Now you could check if there is something new
}
});
我不知道你的聊天是怎么编码的,但我觉得有时间戳。只要检查一下是否有
部门
var compareMe = $('#chat').find('.entry span').last().attr('class');
var compareOther = $(data).find('.entry span').last().attr('class');
就我而言
部门
id="chat"
这个有
部门
class="entry
span
用一个
class="1504155239"
举个例子:
var compareMe = $('#chat').find('.entry span').last().attr('class');
console.log(compareMe);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="chat">
<div class="entry">
<span class="1504155239">1504155239: </span>
Hello There! First!
</div>
<div class="entry">
<span class="1504155254">1504155254: </span>
Hey! Ah, I'm second?
</div>
</div>
compareMe
和
compareOther
相同或更新。
// Lets cast them first to int because of reasons.
// Just kidding, it's safer to cast them and then check if they are newer
compareMe = parseInt(compareMe);
compareOther = parseInt(compareOther);
if (compareMe != compareOther && compareMe > compareOther) {
// Now you can reload.
}
这段代码无效!
setInterval(function(){ // This is the loop function
$.ajax({
url: '<YOUR URL HERE>',
type: 'GET',
success: function(data) {
var check = $(data).find('#chat');
// Here you get the `div` -> `#chat`
var compareMe = $('#chat').find('.entry span').last().attr('class');
var compareOther = $(check).find('.entry span').last().attr('class');
// Now you could check if there is something new
// Lets cast them first to int because of reasons.
// Just kidding, it's safer to cast them and then check if they are newer
compareMe = parseInt(compareMe);
compareOther = parseInt(compareOther);
if (compareMe != compareOther && compareMe > compareOther) {
// Now you can reload.
}
}
});
}, 15000); // The loop function will check every 15 seconds
<脚本src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js“>lt;/script>
你好!第一
<span class=“1504155254”>1504155254:</span>
嘿啊,我是第二?
</div>
HTML
在这里,我可以更具体地帮助你。
这是一个代码示例。
setInterval(function() {
$.ajax({
url: '/',
type: 'GET',
success: function(data) {
var check = $(data).find('.chat77');
var compareMe = $('.chat77').find('li').last().text();
var compareOther = $(check).find('li').last().text();
if (compareMe != compareOther && $('.chat-input').find('input').first().val() == "") {
location.reload();
}
}
});
}, 3000);
我希望您在消息中添加一个时间戳并对此进行检查,而不是
string