我这里有一个问题:我正在创建一个涉及规划的项目。用户在特定时间计划一个特定节目,并使用 PHP 提交到数据库 MySQL。
我希望系统在到达计划时间或距离时间还有几分钟时发出警报。
类似的东西
if ($selectedDate==CURDATE() $$ selectedTime==CURTIME()){
// some ajax to provide popup
}
我将不胜感激有用的帮助。谢谢。
最佳答案
您需要创建一个全局变量来存储事件列表,但不确定您要使用什么类型。您将从 ajax 调用填充变量(这样您就可以在应用程序的每个页面上执行此操作),然后迭代事件以提示用户。
在页面加载时,您将需要从数据库中获取事件。
$(function()
{
retrieveEvents();
promptEvents();
});
创建一个可以调用以获取事件的函数,并将它们存储到全局变量中。
function retrieveEvents()
{
// Make ajax call to get all events
// Wait 1 minute, calls the function again to get new events
setTimeout( "retrieveEvents()" , 60000 ); //60000 = 1 minute
}
然后您将需要一个函数来提示事件
function promptEvents()
{
// At this point you will iterate the global variable of events
// You can check if the event is 2 minutes away, or 5 seconds away
// In those cases, you would then show a modal or alert box.
// Wait 5 seconds, call this method again
setTimeout( "promptEvents()" , 5000 ); //5000 = 5 seconds
}
关于php - 使用 PHP 的 Ajax 时间警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10144512/