zoukankan      html  css  js  c++  java
  • jquery $.ajax 获取josn数据

        <script type="text/javascript" src="jquery-1.9.1.js"></script>
        <script type="text/javascript">
            function test() {
                $.ajax({
                    type: "get",
                    cache: false,
                    url: "../../ajax/Task.aspx",
                    data: 'id =1', // URL后面参数
                    success: function (json) {
                        json = eval("(" + json + ")");
                        $.each(json, function (i, item) {
                            
                            alert(parseInt(item.iname), parseInt(item.iid));
                        });
                    },
                    error: function (msg) {
                        alert("错误:" + msg);
                    }
                });
            }
        </script>
    后台代码:
    public void ProcessRequest(HttpContext context)//只是大概个例子 为了学习
    {
            context.Response.ContentType = "application/json";
            string[] Arraya = new string[] { "张三", "李四", "王二", "赵五" };
            string returns = "";
            returns = "{"people":[";
            for (int i = 0; i < Arraya.Length; i++)
            {
                returns += "[{"iname":"" + Arraya[i] + "","iid":"001"}]" + (i != (Arraya.Length - 1) ? "," : "");
            }
            returns += "]};";
            context.Response.Write(returns);//返回之后 就是上面js里直接定义的json格式
        }
  • 相关阅读:
    SVN 图标消失
    svn 图标不显示
    wamp 局域网访问
    php程序 注册机制
    ThinkphpCMF笔记
    thinkphp缓存
    wampserver与 thinkphp 安装
    js function集合
    php function集合
    php sleep
  • 原文地址:https://www.cnblogs.com/chenghu/p/3928162.html
Copyright © 2011-2022 走看看