aspx頁面:
$(document).ready(function(){
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>");
});
});
}
GetFromDB.aspx頁面:
protected void Page_Load(object sender, EventArgs e)
{
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();
}
本文轉自 韬光星夜 51CTO部落格,原文連結:http://blog.51cto.com/xfqxj/477084,如需轉載請自行聯系原作者