I am trying to call my custom Htpp Handler and want to pass some parameter's but i am unable to retrieve those param's value on the http Handler process request method. I use code like ..
At Client Side
$.ajax({
url: 'VideoViewValidation.ashx',
type: 'POST',
data: { 'Id': '10000', 'Type': 'Employee' },
contentType: 'application/json;charset=utf-8',
success: function (data) {
debugger;
alert('Server Method is called successfully.' + data.d);
},
error: function (errorText) {
debugger;
alert('Server Method is not called due to ' + errorText);
}
});
And this is on my custom http Handler
public class VideoViewValidation : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string videoID = string.Empty;
string id = context.Request["Id"];
string type = context.Request["Type"];
}
}
Please tell me where is the problem .
Remove "contentType: 'application/json;charset=utf-8'" and add "dataType:'json'"
Darm's answer was correct, but just to be clearer about why this works...
You need to remove the line contentType: 'application/json;charset=utf-8' so that $.ajax() uses the default of contentType: 'application/x-www-form-urlencoded; charset=UTF-8' (as specified in the docs for $.ajax). By doing this alone, your code sample should work (the dataType parameter actually specifies the data type that you're expecting to be returned from the server).
In its simplest form, you could write the $.ajax() call like this:
$.ajax({
url: 'VideoViewValidation.ashx',
data: { 'Id': '10000', 'Type': 'Employee' },
});
In this case, the request would be made via GET and the parameters would be sent via the query string, but it still works with context.Request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With