使用ajax post方法进行用户验证 [英] User Validation using ajax post method
问题描述
嗨frens,
i有这个小问题,
i想要从ajax post方法验证用户但我无法弄清楚这段代码,请帮帮我,我有代码喜欢这个
在主页面上我有登录的链接,弹出html表和onclick的提交按钮我称之为jquery调用这样的ajax post方法的函数
hi frens,
i have this small problem,
i want to validate user from ajax post method but i cannot figure out with this code, please help me i have code like this
in the masterpage i have link for signin which pop ups the html table and onclick of the submit button i have called jquery function which calls the ajax post method like this
$(document).ready(function () {
$('#btnSubmit').click(function () {
ValidateUser();
});
});
验证用户的ajax方法
unction ValidateUser( ){
调试器;
var username = $(#txtUsername)。val();
var password = $(# txtPassword)。val();
$ .ajax
({
类型:POST,
url:MasterPage.master / UserValidation,
dataType:json,
数据:{'username':'+ $ username +','password':'+ $ password +'},
contentType:application / json; charset = utf-8,
成功:功能(结果){
alert(result.d);
提醒('登录成功');
},
错误:功能(结果){
alert(result.d) ;
提醒('Invalide用户名或密码');
}
});
};
在masterpage后面的代码中我有一个像这样的webmethod,它具有检查是否有的功能用户是否有效
the ajax method to validate user
unction ValidateUser() {
debugger;
var username = $("#txtUsername").val();
var password = $("#txtPassword").val();
$.ajax
({
type: "POST",
url: "MasterPage.master/UserValidation",
dataType: "json",
data: "{'username':'" + $username + "','password':'" + $password + "'}",
contentType: "application/json; charset=utf-8",
success: function (result) {
alert(result.d);
alert('Login Successful');
},
error: function (result) {
alert(result.d);
alert('Invalide Username or Password');
}
});
};
in the code behind of masterpage i have a webmethod like this that has function to check if the user is valid or not something like this
[WebMethod()]
public int UserValidation(string username, string password)
{
int i = 0;
DataTable dt = Usr.ValidateUser(username, password);
if (dt.Rows.Count > 0)
{
i++;
return i;
}
else
return i;
}
什么是我的错误请帮助我要感谢大家!!!
what is my error please help me out thanks guys!!!
推荐答案
(document).ready(function(){
(document).ready(function () {
(' #btnSubmit')。click(function(){
ValidateUser();
}) ;
});
('#btnSubmit').click(function () { ValidateUser(); }); });
验证用户的ajax方法
unction ValidateUser(){
debugger;
var username =
the ajax method to validate user
unction ValidateUser() {
debugger;
var username =
(#txtUsername)。val();
var password =
("#txtUsername").val();
var password =
这篇关于使用ajax post方法进行用户验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!