动态调用数据的AJAX+JQuery方法

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();
    }

你可能感兴趣的:(jquery,Ajax,职场,aspx,休闲)