//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>