jQuery-ajax
前端
$(function () { var opt = 'GetMember'; var receive_url = 'Register.aspx'; var data = { 'opt': opt }; var myJSONObject = ''; $.ajax({ type: 'GET', url: receive_url, data: data, success: function (data) { myJSONObject = eval('(' + data + ')'); createHtml(myJSONObject); } }); }); function createHtml(data) { var html = ''; for (var i = 1; i < data.length; i++) { var rect = data[i]; html += "<tr>"; html += "<td>" + rect.MEMBERID + "</td> <td>" + rect.MEMBER + "</td> <td>" + rect.DESCRIPTION + "</td> <td><a href='#' onclick=''>删除</a></td>"; html += "</tr>"; } $('#Member').append(html); }
客户端
public void GetMmeber() { string SQL_GetMember = "SELECT MemberId,Member,Description FROM PM_Member"; DataSet ds_GetMember = DBhelper.Query(SQL_GetMember); string json = ""; json = "["; for (int i = 0; i < ds_GetMember.Tables[0].Rows.Count; i++) { json += "{MEMBERID:'" + ds_GetMember.Tables[0].Rows[i]["MEMBERID"].ToString() + "',MEMBER:'" + ds_GetMember.Tables[0].Rows[i]["MEMBER"].ToString() + "',DESCRIPTION:'" + ds_GetMember.Tables[0].Rows[i]["DESCRIPTION"].ToString() + "'}"; if (i != ds_GetMember.Tables[0].Rows.Count -1) { json += ","; } } json += "]"; //string json = Transform2JSON.ToJSONString(ds_GetMember.Tables[0],ds_GetMember.Tables[0].Rows.Count); //string json = Transform2JSON.OSToJSONString(ds_GetMember.Tables[0]); Response.Write(json); Response.End(); }