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("老王");
积累小的知识,才能成就大的智慧,希望网上少一些复制多一些原创有用的答案