zoukankan      html  css  js  c++  java
  • json 异步传输信息给 aspx页面

    在controller里面写一个object返回类型的方法:如下

            public object CoustomLabelWikiReuslt()
            {
                IDictionary<int, string> CoustomLabels = GetCoustomLabel();
                IDictionary<int, int> LabelWikiCount = GetLabelWikiCount();
                IList<int> ids = new List<int>();
                IList<int> counts = new List<int>();
                IList<string> names = new List<string>();
                foreach (int k in CoustomLabels.Keys)
                {
                    ids.Add(k);
                    counts.Add(LabelWikiCount[k]);
                    names.Add(CoustomLabels[k]);
                }
                return Json(new
                {
                    IDS = ids,
                    Names = names,
                    wikiCount = counts,
                }, JsonRequestBehavior.AllowGet);
            }

    这方法的return Json对象,传输三列数据,一一对应的三列数据。

    在aspx页面的js代码里面写下面代码:

     $.get("/wiki/CoustomLabelWikiReuslt", function (data) {
                if (data != null) {
                    if (data.IDS.length > 0) {
                        for (var i = 0; i < data.IDS.length; i++) {
                            $("#wikilabel ul").append("<li><a href='/wiki/search/id?lab=" + data.IDS[i] + "'>" + data.Names[i] + "(<span>" +

                            data.wikiCount[i] +  "</span>)</a></li>");
                        }
                    }
                }
      });

    用get方法异步获取对应的controller里面的方法,data会带回传回的值,也就是return的Json里面的new对象,所以data包含三列数据:IDS、Names、wikiCount

    最后用for循环取三列的值,完美实现

  • 相关阅读:
    [資料]VS2008技巧
    [資料]MarshalAs的用法
    MS SQL Server 2000安装不成功的原因
    Zend產品線
    [轉]Flex 开发必备10武器
    [轉]C#中的XML注释
    [轉]onpropertychange事件
    [轉]fckeditor添加自定义按钮
    [資源]Web設計資源以及线框工具
    [轉]JS中showModalDialog 详细使用
  • 原文地址:https://www.cnblogs.com/lmfeng/p/2045372.html
Copyright © 2011-2022 走看看