我有一个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事件或页面加载事件中捕获名称和pwd变量这里是c#中的代码:
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);
}
我似乎无法在c#侧获得用户名和密码,感谢帮助。
以下是我的最终javascript代码c#代码保持不变:
<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>
谢谢Zachary
答案 0 :(得分:1)
您将JSON数据发送到“登录”页面,但是您尝试拉出GET / POST参数。如果要执行此操作,则应将键/值附加到URL(网址:http://localhost:51870/code/Login.aspx?Name=XXXX&Password=YYYYY)或使用此格式传递数据(数据:名称= XXXX&amp;密码= YYYYY)。