前端每隔几秒发送一个请求

<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
var timer;//声明一个定时器
var count = 0;
function test()
{
//每隔500毫秒执行一次add()方法
timer = window.setInterval("add()",500);
}
function add(){
alert(++ count);
if (count == 5)
{
//若是count值达到5,清空定时器
window.clearInterval(timer);
}
}
</SCRIPT>
</head>
<input type="button" value="点击" onclick="test()">
</html>html