你设置一个定时器不是就行了吗?
window.setTimeout(function () {
AJAX();
}, 1000);
你可以在jquery的ajax 提交到handler 里面去更新就不用刷新页面了:
给你一个我自己刚试的例子:
页面上的:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HanderUpdate.aspx.cs" Inherits="HanderUpdate" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="JS/jquery-1.3.2-vsdoc.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$("#update").click(function() {
$.ajax({
type: "post",
url: "Handler/TestHandler.ashx",
data: "text",
success: function(mess) {
if (mess != null) {
$("#name").val(mess);
}
}
});
});
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
我的名字叫:<input id="name" type="text" name="name" value="小明" />
<p>
<input id="update" name="update" type="button" value="更新名称" />
</p>
</div>
</form>
</body>
</html>
提交到handler里的代码:
<%@ WebHandler Language="C#" Class="TestHandler" %>
using System;
using System.Web;
public class TestHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string name = "小红";
context.Response.Write(name);
}
public bool IsReusable {
get {
return false;
}
}
}