jQuery的更新div中的那一刻起表更新 [英] jQuery update div the moment a table is updated
问题描述
这是我第一次来这里,所以我希望我这样做的权利!
This is my first time here, so I hope I'm doing this right!
无论如何,我试图找出办法有jQuery的更新一个div此刻在MySQL表进行更新。我花了几个小时的答案网上搜索一个有力的量,到目前为止,什么都没有。谁能帮我解决这个问题?
Anyway, I'm trying to figure out a way to have jQuery update a div the moment a table in mysql is updated. I've spent a vigorous amount of hours searching online for an answer, and so far, nothing. Can anyone help me out with this problem?
感谢你了!
有一个伟大的日子。
推荐答案
那么你应该采取的步骤是:
Well the steps you should probably take are:
有一段AJAX code,查询服务器的变化(如行数更改或类似的规定)。使用jQuery你可以这样做:
Have a piece of AJAX code that queries the server for a change (like row count changing or something along those lines). Using jQuery you can do that:
function checkUpdates()
{
$.ajax({
type: "POST",
url: 'hasDataChanged.php', // a webservice or other URL that queries the database
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
// return a JSON string like { "hasChanged" : "true" } or something
if (data.hasChanged) {
// data has changed, do something
}
}
});
}
然后就可以使用JavaScript方法的setInterval
调用code每隔几秒钟。这是不现实的即时做到这一点。
Then you can use the Javascript method setInterval
to call the code every few seconds. It is unrealistic to do it instantly.
$(document).ready(function() {
setInterval("checkUpdates()", 3000); // Calls the function every 3 seconds
});
这篇关于jQuery的更新div中的那一刻起表更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!