會員註冊常用的帳號檢查,利用ajax的技術來檢查
會員註冊常用的帳號檢查,利用ajax的技術來檢查。
要準備的材料:
1. html部份
<input name="account" id="account" type="text" maxlength="18" onkeyup="checkRegAcc()" />
<span id="msg_user_name"></span>
2. javascript
checkRegAcc = function (){
if ($('#account').val().length >=4) {
$.ajax( {
url: 'IDValidate.php',
type: 'GET',
data: {
user_name: $('#account').val()
},
error: function(xhr) {
alert('Ajax request 發生錯誤');
},
success: function(response) {
$('#msg_user_name').html(response);
$('#msg_user_name').fadeIn();
}
} );
}else{
$('#msg_user_name').html('');
}
};
3. ajax程式,可用asp.net或php來撰寫。
include_once("includes/sql.php");
$type = ( isset($_POST['type']) ) ? $_POST['type'] : $_GET['type'];
$sql = "SELECT UserName
FROM memberdata
WHERE UserName = '" . str_replace("\'", "''", $_GET['user_name']) . "'";
$rs = $db->db_GetOne($sql);
if($rs['UserName']=='')
{
$ret = "此帳號可以使用";
}
else
{
$ret = "此帳號已經有人使用";
}
echo $ret;