//Json.ashx中代碼public void ProcessRequest(HttpContext context){context.Response.ContentType = "text/plain";JavaScriptSerializer json = new JavaScriptSerializer();string js= json.Serialize(new person() { Name="Anby", Age="20"});context.Response.Write(js);}//前台代碼<script src="Scripts/jquery-1.7.1.min.js"></script><script type="text/javascript">$(function () {$.post("Json.ashx",function(data,state){if (state = "success"){var person = $.parseJSON(data);alert(person.Name);}})});</script>
//Ashx代碼 public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; var str=context.Request["money"].ToString(); context.Response.Write(str); }//前台js代碼<script src="Scripts/jquery-1.7.1.min.js"></script> <script language="javascript" type="text/javascript"> function button1_onclick() { var money = $("#Text1").val(); $.post("Getself.ashx", { "money": money }, function (data, state) { if (state == "success") { alert("這是伺服器返回的"+data); } }); } </script>