zoukankan      html  css  js  c++  java
  • 使用JQuery遍历解析由.ashx返回的json的值

    使用JQuery遍历解析由.ashx返回的json的值

    在网上查找了很多次,都没有发现真正能解决这个问题的。不过后来找到一个方法,试了试还不错,不过有些地方不是太明白,就是.ashx返回的json的字段为何只能使用小写,使用大写就提示没有定义。遍历值之后,动态填充的ul里作为文章列表。如下图:

    jquery code:

    /// <reference path="http://www.cnblogs.com/js/jquery-1.4.2.js" />
    2
     
    3
    $(document).ready(function () {
    4
        $(window.document).ready(function () {
    5
     
    6
            //搜索
    7
            $("#txtsearch").keydown(function (event) {
    8
                if (event.keyCode == 13) {
    9
                    $("#ulnew").html("");
    10
                    //提交关键词进行搜索
    11
                    $.ajax({
    12
                        url: "askCommon.ashx?action=s",
    13
                        type: "post",
    14
                        data: { "key": $("#txtsearch").val() }, //提交表单,相当于CheckCorpID.ashx?ID=XXX
    15
                        datatype: "json",
    16
                        success: function (data) {
    17
     
    18
                            var json = eval(data);
    19
                            var htmlStr = "";
    20
                            $.each(json, function (i, n) {
    21
                                htmlStr += " <li class='cle'><span class='ans-num'>" + n['replaycount'] + "回答</span> ";
    22
                                htmlStr += "  <span class='price'>" + n['questionscore'] + "</span> ";
    23
                                htmlStr += "  <span class='title'>";
    24
                                htmlStr += "        <a  href='view" + n['questionid'] + ".htm' target='_blank'>" + n['title'] + "</a>";
    25
                                htmlStr += "     </span> ";
    26
                                htmlStr += " </li>";
    27
                            });
    28
                            $("#ulnew").html(htmlStr);
    29
     
    30
                        }
    31
                    });
    32
                }
    33
            })
    34
     
    35
        });
    36
    });
    

  • 相关阅读:
    js 比较日期的大小
    日历(从今天起后面的14天)
    数字转大写
    object对象进行深拷贝
    浏览器渲染机制
    t-5.倒计时(秒杀效果)--本地--服务器(待续)
    s-1.rem自适应
    t-3.跑马灯
    t-2.手机端简单轮播(无滑动效果)
    16.弹性布局
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/2000640.html
Copyright © 2011-2022 走看看