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格式
        }
  • 相关阅读:
    MySQL经典面试题--SQL语句
    awk命令
    mysql安装配置
    notepad++使用
    Xshell使用
    说明
    对 MMO 游戏的调研
    对 VR 项目开发流程的调研
    对 Unity 动态加载资源的调研
    对 Unity 太空射击游戏的实践
  • 原文地址:https://www.cnblogs.com/chenghu/p/3928162.html
Copyright © 2011-2022 走看看