前台js:
$(function () {
$.ajax({
url: "/TestAshx/GetJson.ashx",
type: "post",
data: {"name":"张晓儿","age":20,"birth":"2009-12-4"},
success: function (data) {
}
});
});
后台ashx:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/json";
JObject job;
try
{
string name = context.Request["name"];
int age = Convert.ToInt32(context.Request["age"]);
string birth = context.Request["birth"];
job = new JObject { { "msg","成功接收"},{ "state",200} };
}
catch(Exception ex)
{
job = new JObject { {"msg",ex.Message },{ "state",-1} };
}
context.Response.Write(job);
}
测试结果符合预期,接收到了数据。
不知道有没有直接接收实体对象的写法,如果有等我发现了再补上