首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

json处置Javascript 和web服务器端的之间数据交换

2013-07-16 
json处理Javascript 和web服务器端的之间数据交换那位大神给写个json处理Javascript 和web服务器端的之间

json处理Javascript 和web服务器端的之间数据交换
那位大神给写个json处理Javascript 和web服务器端的之间数据交换简单实列啊。。。。 JSON JavaScript
[解决办法]

引用:
那位大神给写个json处理Javascript 和web服务器端的之间数据交换简单实列啊。。。。

asp.net html代码:
<head runat="server">
    <title></title>
    <script src="js/jquery.js" type="text/javascript"></script>
    <script type="text/javascript">
        function getjson() {
            $.getJSON("/ajax/_getjson.ashx", function (data) {
                alert(data.haha[0].ha);
            });

//                        $.ajax({
//                            type: 'post',
//                            dataType: 'json',
//                            contentType: "application/json; charset=utf-8",
//                            url: "/ajax/_getjson.ashx",
//                            success: function (data) {
//                             
//                                alert(data.haha[0].ha);


//                            },
//                            error: function (data) {
//                                alert("error" + data);
//                            }
//                        });

        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="Button1" type="button" value="button" onclick="getjson();" />
    </div>
    </form>
</body>
</html>



一般处理程序:
public void ProcessRequest(HttpContext context)
        {
            //context.Response.ContentType = "text/plain";
            context.Response.ContentType = "application/json";
            context.Response.Write("{"result":"0","haha":[{"ha":"1"}]}");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

要引用jquery脚本:
如果没有引用这个脚本 就用注释的部分

热点排行