setInterval 启用和停止,见代码
<title></title>
<script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var iCount = setInterval(GetBack, 3000);
function GetBack() {
alert("aa");
$.ajax({
type: "POST",
url: "WebForm4.aspx/GetString",
dataType: "text",
contentType: "application/json; charset=utf-8",
beforeSend: function (XMLHttpRequest) {
},
success: function (msg) {
alert("ff");
},
error: function (msg) {
alert(msg);
}
});
}
$("#cOk").click(function (e) {
clearInterval(iCount);
});
});
</script>
<div>
<a href="#" id="cOk" >sss</a>
</div>
后台代码
------------------
[WebMethod]
public static string GetString()
{
return "aa";
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】博客园携手 AI 驱动开发工具商 Chat2DB 推出联合终身会员
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步