zoukankan      html  css  js  c++  java
  • JQuery加载JSON数据 宁静以致远

    // 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+"&nbsp;&nbsp;&nbsp;"+jsonList[i].Region_sc+"<br>";
         })*/
         //方法二:
         $.each(jsonList,function(i,n){
                str+="ID:"+n.Region+"&nbsp;&nbsp;&nbsp;"+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}

  • 相关阅读:
    数据仓库深入了解
    修改hive 默认fs为s3 遇到的坑
    Hadoop集群的各部分常用端口
    mvc结合web应用实例分析
    MVC简介
    关于jQuery获得表单radio类型输入框的选中值
    关于js中的取值问题
    struct2的xml文件中result的配置(转)
    关于http响应状态码
    关于hibernate插入数据到mysql数据库中文乱码问题的解决
  • 原文地址:https://www.cnblogs.com/myjacky/p/2297344.html
Copyright © 2011-2022 走看看