會員註冊常用的帳號檢查,利用ajax的技術來檢查。
要準備的材料:
1. html部份
2. javascript
01 | checkRegAcc = function (){ |
02 | if ($('#account').val().length >=4) { |
04 | url: 'IDValidate.php', |
07 | user_name: $('#account').val() |
09 | error: function(xhr) { |
10 | alert('Ajax request 發生錯誤'); |
12 | success: function(response) { |
13 | $('#msg_user_name').html(response); |
14 | $('#msg_user_name').fadeIn(); |
19 | $('#msg_user_name').html(''); |
3. ajax程式,可用asp.net或php來撰寫。
01 | include_once("includes/sql.php"); |
04 | $type = ( isset($_POST['type']) ) ? $_POST['type'] : $_GET['type']; |
06 | $sql = "SELECT UserName |
08 | WHERE UserName = '" . str_replace("\'", "''", $_GET['user_name']) . "'"; |
09 | $rs = $db->db_GetOne($sql); |
11 | if($rs['UserName']=='') |
13 | $ret = "color:green">此帳號可以使用 |
"
;
17 | $ret = "color:red">此帳號已經有人使用 |
"
;
資料來源
沒有留言:
張貼留言