首页  ·  知识 ·  编程语言
静态页面读取程序页数据
网友  CSDN博客  .NET  编辑:子轩   图片来源:网络
静态页发送异步请求给程序页(可以是aspx或者是ashx),程序页在后台根据请求执行相应的方法,然后返回给静态页

静态页发送异步请求给程序页(可以是aspx或者是ashx),程序页在后台根据请求执行相应的方法,然后返回给静态页.

1.静态页代码:

<script type="text/JavaScript">
        $(function(){
            $.get("
jQuery-table-demo.aspx?action=MemberList", function(msg) {
//                alert(msg);
                var str_Json = msg;
                var str_table = "";
                var json_val = eval("("+str_Json+")");
                $.each(json_val.rows,function(index,item){
                    str_table += "<tr><td>"+item.id+"</td><td>"+item.name+"</td><td>"+item.email+"</td><td>"+item.mobile+"</td></tr>";
                });
                $("tbody").append(str_table);
            });
        })
        
    </script>

<table>
        <thead>
            <tr>
                <th>编号</th>
                <th id="memberName">姓名</th>
                <th>邮箱</th>
                <th>手机</th>
            </tr>
        </thead>
        <tbody>
            
        </tbody>
    </table>

2.程序页代码:

public string strInfo = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["action"] == "MemberList") 
                {
                    GetMember();
                }
                
            }
        }

private void GetMember() 
        {
            DataTable dtInfo = MemberInfo.GetMemberList();
            if (dtInfo.Rows.Count > 0)
            {
                strInfo = "{rows:[";
                //StringBuilder sbInfo = new StringBuilder();
                //sbInfo.Append("{rows:[");
                foreach (DataRow dr in dtInfo.Rows)
                {
                    //sbInfo.Append("{'id':'");
                    //sbInfo.Append(dr["id"].ToString());
                    //sbInfo.Append("',");
                    //sbInfo.Append("'name':'");
                    //sbInfo.Append(dr["username"].ToString());
                    //sbInfo.Append("',");
                    //sbInfo.Append("'email':'");
                    //sbInfo.Append(dr["email"].ToString());
                    //sbInfo.Append("',");
                    //sbInfo.Append("'mobile':'");
                    //sbInfo.Append(dr["mobile"].ToString());
                    //sbInfo.Append("',");
                    strInfo += "{'id':" + "'" + dr["id"].ToString() + "',";
                    strInfo += "'name':" + "'" + dr["username"].ToString() + "',";
                    strInfo += "'email':" + "'" + dr["email"].ToString() + "',";
                    strInfo += "'mobile':" + "'" + dr["mobile"].ToString() + "'},";
                }
                //sbInfo.Remove(sbInfo.Length - 1, 1).Append("]}");
                //strInfo = sbInfo.ToString();
                strInfo = strInfo.Substring(0, strInfo.Length - 1);
                strInfo += "]}";
                Response.Write(strInfo);
                Response.End();
            }
        }


本文作者:网友 来源:CSDN博客
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读