将参数从jQuery.Ajax传递到ASHX Handler [英] Passing parameter from jQuery.Ajax into ASHX Handler

查看:381
本文介绍了将参数从jQuery.Ajax传递到ASHX Handler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,我想使用jQuery.ajax将参数从.js文件传递给ASHX Handler

这是我的js函数

  function  SendPath(输入){
$ .ajax({
' type'' POST'
' url'' ./ Upload.ashx / PathMethod'
' data':{
' name' 程序员'
},
' success' function (msg){
警报(msg.d);
}
});
}





这是我的ASHX WebMethod

< pre lang =HTML> [WebMethod]
公共静态字符串PathMethod(字符串名称){
返回名称;我将参数传递给PathMethod后,
}





 alert(msg。 d); 

是''undefined''。



如何解决这个问题?????

解决方案

.ajax({
' type'' POST'
' url'' ./ Upload.ashx / PathMethod'
' data':{
' name'' 程序员'
},
' success' function (msg){
alert(msg.d);
}
});
}





这是我的ASHX WebMethod

< pre lang =HTML> [WebMethod]
公共静态字符串PathMethod(字符串名称){
返回名称;我将参数传递给PathMethod后,
}





 alert(msg。 d); 

是''undefined''。



如何解决这个问题?????


请参考以下链接



http://www.mikesdotnetting.com/Article/104/Many-ways-to-communicate-with-your-database- using-jQuery-AJAX-and-ASP.NET [ ^ ]


Hello All, i want to pass a parameter from .js file to ASHX Handler using jQuery.ajax
this is my js function

function SendPath(input) {
    $.ajax({
        'type': 'POST',
        'url': './Upload.ashx/PathMethod',
        'data': {
            'name': 'Programmer',
        },
        'success': function (msg) {
            alert(msg.d);
        }
    });
}



and this is my ASHX WebMethod

[WebMethod]
    public static string PathMethod(string name){
        return name;
    }



after I passed parameter to PathMethod, the result of

alert(msg.d);

is ''undefined''.

how can I solve this problem?????

解决方案

.ajax({ 'type': 'POST', 'url': './Upload.ashx/PathMethod', 'data': { 'name': 'Programmer', }, 'success': function (msg) { alert(msg.d); } }); }



and this is my ASHX WebMethod

[WebMethod]
    public static string PathMethod(string name){
        return name;
    }



after I passed parameter to PathMethod, the result of

alert(msg.d);

is ''undefined''.

how can I solve this problem?????


Please refer the link below

http://www.mikesdotnetting.com/Article/104/Many-ways-to-communicate-with-your-database-using-jQuery-AJAX-and-ASP.NET[^]


这篇关于将参数从jQuery.Ajax传递到ASHX Handler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆