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("老王");
原文地址:https://www.cnblogs.com/llcdbk/p/4596119.html