AJAX小练习,防止以后忘记

 <div id="content">
        <input id="btnShow" type="button" value="button" />
    </div>
        <script type="text/javascript">
            $("#btnShow").click(function () {
                $.ajax({
                    url: "handle.ashx",
                    asyn: true,
                    data: { LoginName: "lm", pwd: "mm" },
                    dataType: "json",
                    
                    success: function (msg) {
                        //alert(msg.name);
                        $("#btnShow").after("<h1>" + msg.name + "</h1>");
                    },
                    error: function (data) {

                        alert(data);
                        alert(data.error);
                    }
                });
            });
        </script>

后台:

context.Response.ContentType = "application/json";
            //context.Response.ContentType = "text/plain";
            string name = context.Request["LoginName"].ToString();
            string age = context.Request["pwd"].ToString();
            string json = "{\"name\":\"张三\"}";

            context.Response.Write(json);
            //context.Response.Write("老王");

 

posted @ 2015-06-23 18:56  洛晨随风  阅读(149)  评论(0编辑  收藏  举报