Can't pass jQuery data $ .ajax to ashx handler
This is part of my AJAX code:
$.ajax({
type: "POST",
url: "ajax.ashx?method=LoadCities",
data: "{state_id:'" + state_id + "'}",
contentType: "application/json;charset=utf-8",
dataType: "json",
.
.
.
and this is part of my ASHX handler code:
public class ajax : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "application/json;charset=utf-8";
string method = context.Request["method"];
if (method == "LoadCities")
{
object ss = context.Request.Form["state_id"];
context.Response.Write(LoadCities(ss));
}
}
I cannot get the "state_id" and it is always null
How can I get the "state_id"
+3
source to share
1 answer
You can pass it as a query string,
$.ajax({
type: "POST",
url: "ajax.ashx?method=LoadCities&state_id=" + state_id,
contentType: "application/json;charset=utf-8",
dataType: "json",
... ,.
and get your state_id in your .ashx handler,
string lsStateId = System.Convert.ToString(context.Request.QueryString["state_id"]);
+5
source to share