从jQuery调用将参数传递给Http Handler

前端之家收集整理的这篇文章主要介绍了从jQuery调用将参数传递给Http Handler前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图调用我的自定义Htpp处理程序,并希望传递一些参数但我无法在http处理程序进程请求方法中检索这些param的值.
我用的代码就像..

在客户端

$.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);
                }
            });

这是我的自定义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"];
}
}

请告诉我问题出在哪里.

解决方法

删除“contentType:’application / json; charset = utf-8’”并添加“dataType:’json’”

猜你在找的jQuery相关文章