Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从ajax调用中获取c#中的变量_C#_Jquery_Ajax_Asp.net Ajax - Fatal编程技术网

从ajax调用中获取c#中的变量

从ajax调用中获取c#中的变量,c#,jquery,ajax,asp.net-ajax,C#,Jquery,Ajax,Asp.net Ajax,我有一个Ajax登录调用,代码如下: //if MOUSE class is clicked $('.mouse').click(function () { //get the form to submit and return a message //how to call the function var name = $('#name').val(); var pwd2 = $('#pwd2').val(); $.ajax({ type:

我有一个Ajax登录调用,代码如下:

//if MOUSE class is clicked
$('.mouse').click(function () {
    //get the form to submit and return a message
    //how to call the function 

    var name = $('#name').val();
    var pwd2 = $('#pwd2').val();
    $.ajax({
    type:"POST",               
     url: "http://localhost:51870/code/Login.aspx",
     data: "{ 'name':'" + $('#name').val() + "', 'pwd':'" + $('#pwd2').val() + "' }",
     contentType: "application/json; charset=utf-8",
     dataType: "json",
     context: document.body, 
     success: function () {
        //$(this).addClass("done");
        $(this).hide();
         $('.mouse, .window').hide();
                         }
});

});
问题是我似乎无法在登录页面的preinit事件或页面加载事件中捕获name和pwd变量这里是c#中的代码:

我似乎无法在c#side中获取用户名和密码,非常感谢您的帮助

这是我最后的javascript代码c#代码保持不变:


$(文档).ready(函数(){
//如果单击鼠标类
$('.mouse')。单击(函数(){
var name=$('#name').val();
var pwd=$('#pwd').val();
$.ajax({
url:“http://localhost:51870/code/Login.aspx?name=“+name+”&pwd=“+pwd,
上下文:document.body,
成功:函数(){
//$(此).addClass(“完成”);
$(this.hide();
$('.mouse,.window').hide();
}
});
});
});

感谢Zachary将JSON数据发送到登录页面,但您试图提取GET/POST参数。如果要执行此操作,应将键/值附加到URL(URL:)或使用此格式(数据:Name=XXXX&Password=yyyy)传递数据

 protected void Page_PreInit(object sender, EventArgs e)
{
    //taking javascript argument in preinit event
    //from here I'll have to build the page for specific lookbook
    var name = Request.QueryString["name"];
    var pwd = Request.QueryString["pwd"];

}

protected void Page_Load(object sender, EventArgs e)
{
    var name = Request.QueryString["name"];
    var pwd = Request.QueryString["pwd"];
    SignIn(name);
}
<script type="text/javascript">

        $(document).ready(function () {    
 //if MOUSE class is clicked
            $('.mouse').click(function () {

                var name = $('#name').val();
                var pwd = $('#pwd').val();
                $.ajax({
               url: "http://localhost:51870/code/Login.aspx?name="+ name +"&pwd="+pwd,
               context: document.body, 
               success: function () {
                    //$(this).addClass("done");
                    $(this).hide();
                     $('.mouse, .window').hide();
                                     }
            });

            });

     });
</script>