$(function () {
$("#btnget").click(function () {
$.ajax({
type: "post",
dataType: "json",
url: "data.ashx",
success: function (msg) {
var str = "";
for (i in msg) {
str += "
" + msg[i].id + "
"
+ msg[i].name + "
" + msg[i].cla +
"
" + msg[i].sex + "
" +
msg[i].tel + "
";
}
$("tbody").append(str);
}
});
});
});
为了使表格好看一些,我们定义一下它的样式
然后写服务器端返回json数据的代码
string data =
"[{\"id\":\"2010324268\",\"name\":\"林宇\",\"cla\":\"10软件\",\"sex\":\"男\",\"tel\":\"13800138000\"},{\"id\":\"2010324256\",\"name\":\"李四\",\"cla\":\"10网络\",\"sex\":\"女\",\"tel\":\"10010\"},{\"id\":\"2010324264\",\"name\":\"张三\",\"cla\":\"10软件\",\"sex\":\"男\",\"tel\":\"10086\"}]";
context.Response.Write(data);