i have an ASP.NET 4.0 HTTP handler that should receive and send data in json format. I’m using jquery to send json objects serialized in a string to the handler. It correctly sends the request but i don’t know how i could retrieve the data from the httpcontext passed to the handler and how i could deserialize it… …
via Asp.Net Developed Tutorials » Search Results » ajax:
Send JSON data to ASP.NET HTTP Handler
i have an ASP.NET 4.0 HTTP handler that should receive and send data in json format. I’m using jquery to send json objects serialized in a string to the handler. It correctly sends the request but i don’t know how i could retrieve the data from the httpcontext passed to the handler and how i could deserialize it… Can someone help me?
UPDATE 1
$.ajax(
type: “POST”,
url: “myurl.ashx”,
dataType: “json”,
contentType: “application/json; charset=utf-8″,
data: $.toJSON(
…
),
success: function (response)
…
});
…………………………………………
Do you send the data from jquery as a POST or GET request? In your Http Handler you can retrieve the values through the HttpContext.Request either via Forms or QueryString
ie. string json = HttpContext.Current.Request.Forms[“json”];
To deserialize you can use the built in System.Web.Script.Serialization.JavaScriptSerializer class like this
string json = HttpContext.Current.Request.Forms[“json”];
var js = new JavaScriptSerializer();
YourType obj = js.Deserialize
For more info: Send JSON data to ASP.NET HTTP Handler
Asp.Net Developed Tutorials » Search Results » ajax