aspx页面:
$(document).ready(function(){
setInterval("GetData()",100);
});
function GetData()
{
setInterval("GetData()",100);
});
function GetData()
{
$.getJSON("GetFromDB.aspx?usercode=6&telnum=13003930624",function(json){
$.grep(json,function(temp){
$("#dvUser").empty();
$("#dvUser").append("<div title='"+temp.state+"'>"+temp.info+"</div>");
});
});
}
$.grep(json,function(temp){
$("#dvUser").empty();
$("#dvUser").append("<div title='"+temp.state+"'>"+temp.info+"</div>");
});
});
}
GetFromDB.aspx页面:
protected void Page_Load(object sender, EventArgs e)
{
Response.Expires = -1000;
DataTable dt=从数据库获取的数据;
{
Response.Expires = -1000;
DataTable dt=从数据库获取的数据;
if (dt == null)
{
Response.End();//不要忘记这个,不然输出一大串html代码
return;
}
string json = "";
Response.Write("[");
for (int i = 0; i < dt.Rows.Count; i++)
{
json += (json.Length > 0 ? "," : "") +"{info:'" + dt.Rows[i]["StateInfo"].ToString() + "',state:'" + dt.Rows[i]["iState"].ToString() + "'}";
}
Response.Write(json + "]");
Response.End();
}
{
Response.End();//不要忘记这个,不然输出一大串html代码
return;
}
string json = "";
Response.Write("[");
for (int i = 0; i < dt.Rows.Count; i++)
{
json += (json.Length > 0 ? "," : "") +"{info:'" + dt.Rows[i]["StateInfo"].ToString() + "',state:'" + dt.Rows[i]["iState"].ToString() + "'}";
}
Response.Write(json + "]");
Response.End();
}
本文转自 韬光星夜 51CTO博客,原文链接:http://blog.51cto.com/xfqxj/477084,如需转载请自行联系原作者