//执行setTimeOut函数返回的ID var timeOutCount; //周期(以毫秒/ms为单位),平均每3秒刷新一次 var timeCycle = 3000; $(function () { getData(); }); //向服务器发送请求,并获取返回结果 function getData() { $.ajax({ type: 'GET', url: '...', dataType: "json", global: false, success: function (data) { /*TO DO*/ timeOutCount = setTimeout(getData, timeCycle); }, error: function (data) { timeOutCount = setTimeout(getData, timeCycle); } }); } //停止 function stop() { if (timeOutCount > 0) { removeTimeOut(timeOutCount); } } //清空TimeOut function removeTimeOut(id) { window.clearTimeout(id); }