ajax 登录功能简单实现(未连接数据库)
时间:2021-07-11 08:42:35|栏目:JavaScript代码|点击: 次
简单的登录功能(未连接数据库)
<script src="Jquery1.7.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#tijiao').click(function () {
var username = $('#username').val();
var pwd = $('#pwd').val();
$.ajax({
type: "post",
contentType: "application/json",
url: "WebService1.asmx/denglu",
data: "{username:'" + username + "',pwd:'" + pwd + "'}",
success: function (bukeyi) {
$('#tishi').text(bukeyi.d);
}
})
})
})
</script>
</head>
<body>
用户名:<input type="text" id="username" runat="server" />
密码:<input type="text" id="pwd" runat="server" />
<input type="button" id="tijiao" value="提交" />
<div id="tishi"></div>
[WebMethod]
public string denglu(string username,string pwd)
{
if (username == "zhangsan" && pwd == "123")
{
return "登陆成功!";
}
else { return "登陆失败!"; }
}
复制代码 代码如下:
<script src="Jquery1.7.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#tijiao').click(function () {
var username = $('#username').val();
var pwd = $('#pwd').val();
$.ajax({
type: "post",
contentType: "application/json",
url: "WebService1.asmx/denglu",
data: "{username:'" + username + "',pwd:'" + pwd + "'}",
success: function (bukeyi) {
$('#tishi').text(bukeyi.d);
}
})
})
})
</script>
</head>
<body>
用户名:<input type="text" id="username" runat="server" />
密码:<input type="text" id="pwd" runat="server" />
<input type="button" id="tijiao" value="提交" />
<div id="tishi"></div>
[WebMethod]
public string denglu(string username,string pwd)
{
if (username == "zhangsan" && pwd == "123")
{
return "登陆成功!";
}
else { return "登陆失败!"; }
}