|
 |
|
สอบถามวิธีใช้ jquery ในการล็อคอิน โดยไม่เปลี่ยนหน้าครับ ถ้าใส่รหัสถูก ให้โชว์อีกแบบ ถ้าใส่ผิดให้กรอกใหม่ แต่มีข้อความเตือนว่าผิดครับ |
|
 |
|
|
 |
 |
|
login ไม่เหมาะทำ ajax นะครับ ควรส่งเข้าโปรแกรม
เพื่อกำหนด Session cookie หรืออะไรก็ตามให้ถูกต้องก่อนครับ
|
 |
 |
 |
 |
Date :
2014-07-11 21:01:26 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันนี้เป็น CODE ตัวอย่างครับ
Code (PHP)
<script>
$(document).ready(function(){
$("#add_err").css('display', 'none', 'important');
$("#login").click(function(){
username=$("#name").val();
password=$("#word").val();
$.ajax({
type: "POST",
url: "login.php",
data: "name="+username+"&pwd="+password,
success: function(html){
if(html=='true') {
//$("#add_err").html("right username or password");
window.location="dashboard.php";
}
else {
$("#add_err").css('display', 'inline', 'important');
$("#add_err").html("<img src='images/alert.png' />Wrong username or password");
}
},
beforeSend:function()
{
$("#add_err").css('display', 'inline', 'important');
$("#add_err").html("<img src='images/ajax-loader.gif' /> Loading...")
}
});
return false;
});
});
</script>
<div class="loginform-in">
<h1>User Login</h1>
<div class="err" id="add_err"></div>
<fieldset>
<form action="./" method="post">
<ul>
<li> <label for="name">Username </label>
<input type="text" size="30" name="name" id="name" /></li>
<li> <label for="name">Password</label>
<input type="password" size="30" name="word" id="word" /></li>
<li> <label></label>
<input type="submit" id="login" name="login" value="Login" class="loginbutton" ></li>
</ul>
</form>
</fieldset>
</div>
login.php
Code (PHP)
session_start();
$uName = $_POST['name'];
$pWord = md5($_POST['pwd']);
$qry = "SELECT usrid, username, oauth FROM usermeta WHERE username='".$uName."' AND pass='".$pWord."' AND status='active'";
$res = mysql_query($qry);
$num_row = mysql_num_rows($res);
$row=mysql_fetch_assoc($res);
if( $num_row == 1 ) {
echo 'true';
$_SESSION['uName'] = $row['username'];
$_SESSION['oId'] = $row['orgid'];
$_SESSION['auth'] = $row['oauth'];
}
else {
echo 'false';
}
คือ Return ค่า True หรือ False กลับมา เพื่อนำมาแสดงผลตามต้องการ
|
ประวัติการแก้ไข 2014-07-11 22:35:11
 |
 |
 |
 |
Date :
2014-07-11 22:33:32 |
By :
asustak |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|