ashx receives data transmitted from the front desk

 

Reception js:

$(function () {
$.ajax({
url: "/TestAshx/GetJson.ashx",
type: "post",
data: {"name":"张晓儿","age":20,"birth":"2009-12-4"},
success: function (data) {
}
});
});

Background 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);
}

 

The test results in line with expectations, the data received.

I do not know there is no direct wording receiving entity object, if there is an important qualification, etc. I found on

Guess you like

Origin www.cnblogs.com/yagamilight/p/11991128.html