簡單的登錄功能(未連接數據庫)
復制代碼 代碼如下:
<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 "登陸失敗!"; }
}