Ajax动态请求,控制页面显示

前端之家收集整理的这篇文章主要介绍了Ajax动态请求,控制页面显示前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Ajax隔固定时间请求后台,控制页面显示

<script type="text/javascript">
$(function () {
setInterval("getNews()",5000); //每隔5秒刷新
});
function getNews() {
var data = "";
$.ajax({
type: "post",
url: "/Ajax/AjaxRefresh.ashx",
success: function (str) {
var s = str;
var objs = document.getElementById("uc2_TreeView1").getElementsByTagName("a");
for(var i = 0; i < objs.length; i++){
if(objs[i].innerText=="我的会签"){
if (s[0] == "1") {
//var img = document.createElement("img");
//img.src="images/sign.gif";
//objs[i].appendChild(img);
objs[i].innerHTML = "我的会签<img src='images/sign.gif' style='height:30px;'/>";
} else if (s[0] == "0") {
objs[i].innerHTML = "我的会签";
}
}
} else if (objs[i].innerText == "我的任务") {
if (s== "1" ) {
objs[i].innerHTML = "我的任务<img src='images/sign.gif' style='height:30px;'/>";
}
}
}
}
});
}
</script>



public class AjaxRefresh : IHttpHandler,IRequiresSessionState {



public void ProcessRequest (HttpContext context) {
string result = "";
User user = (User)context.Session["User"];
if (user == null)
{
HttpContext.Current.Response.Redirect("~/Default.aspx");
}
context.Response.ContentType = "text/plain";
string sql_search = "select tb_task.taskID,tb_task.tableID,tb_task.taskName,tb_task.proNum,tb_task.proName,tb_task.applyerName,tb_task_sign.* from tb_task,tb_task_sign where tb_task.taskID=tb_task_sign.taskID and tb_task_sign.signerResult is NULL and tb_task_sign.signerID=" + user.UserID;
DataTable dt = MyDBInterface.getTableByText(sql_search);
if (dt.Rows.Count > 0)
{
result += "1";
}
else {
result += "0";
}

context.Response.Write(result);

}

}

效果

原文链接:https://www.f2er.com/ajax/162152.html

猜你在找的Ajax相关文章