// JScript 文件
$(document).ready(function(){
$("#divJson").html("<font color=green>数据加载中。。。</font>");
$.getJSON("MyAjax.aspx",function(json){
var str="";
var jsonList =json.list;
//方法一:
/*$.each(jsonList,function(i){
str+="ID:"+jsonList[i].Region+" "+jsonList[i].Region_sc+"<br>";
})*/
//方法二:
$.each(jsonList,function(i,n){
str+="ID:"+n.Region+" "+n.Region_sc+"<br>";
})
$("#divJson").html(str);
$("#divPage").html("共有记录数:"+json.totalRecord);
});
})
Ajax.aspx
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Clear()
Response.ContentType = "application/json"
Dim dsJson As DataSet = GetSqlDataSet()
Dim list As New List(Of RegionModel)
For i As Integer = 0 To dsJson.Tables(0).Rows.Count - 1
Dim model As New RegionModel()
model.Region = dsJson.Tables(0).Rows(i)("Region")
model.Region_sc = dsJson.Tables(0).Rows(i)("Region_sc")
list.Add(model)
Next
Dim str As String = Newtonsoft.Json.JavaScriptConvert.SerializeObject(list)
Dim json As String = "{""list"":" & str & ",""totalRecord"":" & list.Count & "}"
Response.Write(json)
Response.End()
End Sub
//json数据格式
{"list":[{"Region":"PCC001","Region_sc":"华中"},
{"Region":"FJ0001","Region_sc":"福建"},
{"Region":"EX0001","Region_sc":"出口"},
{"Region":"GZ0001","Region_sc":"广州"},{"Region":"HK0001","Region_sc":"香港"},
{"Region":"KQ","Region_sc":"跨区"},{"Region":"L20056","Region_sc":"珠海/中山"},
{"Region":"MC0001","Region_sc":"澳门"},{"Region":"PEC001","Region_sc":"华东"},
{"Region":"PNC001","Region_sc":"华北"},{"Region":"PSC001","Region_sc":"华南"},
{"Region":"PWC001","Region_sc":"华西"},{"Region":"SZ0001","Region_sc":"深圳"}],"totalRecord":13}