ajax 登录功能简单实现(未连接数据库)
(编辑:jimmy 日期: 2024/11/17 浏览:3 次 )
简单的登录功能(未连接数据库)
复制代码 代码如下:
<script src="/UploadFiles/2021-04-02/Jquery1.7.js"><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="/UploadFiles/2021-04-02/Jquery1.7.js"><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 "登陆失败!"; }
}
下一篇:滑轮滚动到页面底部ajax加载数据配合jsonp实现探讨