js定时器
每天早上9点执行一个方法,js如何实现,定时
[解决办法]
就是判断当前日期
d = new Date()
的时分秒
[解决办法]
js是在客户端运行的,必须保证浏览器一直打开
[解决办法]
setInterval能做到吗?需要用到AJAX吗?
[解决办法]
setInterval 函数即可
[解决办法]
function callAjax() {$.post("../json/smxj.ashx", "", function (data) { var obj = eval(data); var user_name = ""; var nick_name = ""; var server_id = ""; $.each(obj, function (key, objs) { user_name += objs.user_name.replace('is_', '') + ","; nick_name += objs.nick_name + ","; server_id += objs.server_id + ","; }); $.post("../json/smxj_1.ashx", { user_name: user_name, nick_name: nick_name, server_id: server_id }, function (data) { alert(data); }); } );} function doIt() { d = new Date(); if (d.getHours() == 9 && d.getMinutes() == 0 && d.getSeconds() == 0) { callAjax(); } } window.setInterval("doIt()", 1000);