1
這裏是我的C#代碼檢查用戶名或密碼真或使用jQuery的web服務假
public void Login(string kullaniciAd, string sifre)
{
try
{
SqlConnection conn = new SqlConnection("Data Source=.\\SQLExpress; Initial Catalog=twitter;Integrated Security=SSPI");
if (conn.State == ConnectionState.Closed)
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM tblKullanici WHERE kullaniciAdi = @kullaniciAd or sifre = @kullaniciSifre", conn);
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
cmd.Parameters.AddWithValue("@kullaniciAd", kullaniciAd);//username
cmd.Parameters.AddWithValue("@kullaniciSifre", sifre); //password
cmd.ExecuteNonQuery();
int UserExist = (int)cmd.ExecuteScalar();
if (UserExist > 1)
{
//if given there is a user with given username and password??
// i don't know how to do that first should i check username and then check that username's password or what??
//successful
}
else
{
//wrong password or username
}
conn.Close();
}
catch (SoapException se)
{
throw se;
}
}
,這裏是我的aspx頁面
<script>
$(document).ready(function() {
$('#btnLogin').click(login);
});
function login() {
var kullaniciAd = $('#userName').val();
var sifre = $('#password').val();
$.ajax({
url: "http://localhost:63000/LoginService.asmx/Login",
type: "POST", //or should it be GET?
dataType: "json",
data: JSON.stringify({ kullaniciAd: kullaniciAd, sifre: sifre }),
contentType: "application/json; charset=windows-1254",
success: function() {
alert("");// i have an alert div down there how can i show if login is successful or not in that alert div
},
error: function (e) {
alert(e.statusText);
}
})
}
</script>
<%--<div class="alert alert-danger alert-dismissable">
<button contenteditable="false" type="button" class="close" data-dismiss="alert"
aria-hidden="true">
×</button>
<strong>Well done!</strong>You successfully read this important alert message.
</div>--%>
它似乎很容易,但我不能決定如果我檢查真實或錯誤的Web服務,只發送jquery只有一個數據(true,false)或檢查是否true或false在jquery中調用true或false web方法?