鉴于大家对Ajax十分关注,我们编辑小组在此为大家搜集整理了“ajax 登录功能简单实现(未连接数据库)”一文,供大家参考学习
简单的登录功能(未连接数据库)
复制代码 代码如下:
<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 "登陆失败!"; }
}