這段代碼像在Facebook中 正在發生變化的用戶名我有這個代碼的問題:如何通過jQuery的
$(function(){
var uid = 1;
var name_available=0;
var password_ok=0;
$('#name,#password').bind('keyup',function(){
var name = $('#name').val();
var password = $('#password').val();
if(/[^a-zA-Z_\.0-9]+/.test(name)){
$('#result').html('Invalid Charcters');
name_available = 0;
}else{
$.ajax({
url: 'check_user.ajax.php',
type: 'POST',
data: 'name='+name,
success: function(data){
if(data){
$('#result').html('available');
name_available = 1;
}else{
$('#result').html('not available');
name_available = 0;
}
}
});
}
$.ajax({
url: 'check_user.ajax.php',
type: 'POST',
data: 'uid='+uid+'&password='+password,
success: function(data){
if(data){
$('#result2').html('true');
password_ok = 1;
}else{
$('#result2').html('false');
password_ok = 0;
}
}
});
if(name_available === 1 && password_ok === 1){
$('#save').removeAttr('disabled');
}else{
$('#save').attr('disabled','disabled');
}
});
});
和HTML代碼是:
username:<input type="text" name="name" value="" id="name" /><span id="result"></span><br />
password:<input type="password" name="password" value="" id="password" /><span id="result2"></span><br />
<input type="submit" name="save" value="save changes" id="save" disabled /><br />
和ajax.php Oage是:
include 'config.php';
if(isset($_POST['name'])){
$name = $_POST['name'];
if(!empty($name)){
$sel = mysql_query("SELECT `id` FROM `users` WHERE `name`='$name'");
$num = mysql_num_rows($sel);
if($num > 0){
echo false;
}else{
echo true;
}
}else{
echo false;
}
}else{
echo false;
}
if(isset($_POST['password']) && isset($_POST['uid'])){
$uid = $_POST['uid'];
$password = md5($_POST['password']);
$sel = mysql_query("SELECT `id` FROM `users` WHERE `id`='$uid' AND `password`='$password'");
$num = mysql_num_rows($sel);
if($num < 1){
echo false;
}else{
echo true;
}
}else{
echo false;
}
該代碼的作品,但不是所有的時候更改用戶名或pa ssword然後更改用戶
請幫助我,它對我很重要。
我的代碼是用來檢查用戶名是否可用,如果用戶名可用,並且他在這種情況下鍵入他的(舊)密碼true,則從提交按鈕中刪除屬性「disabled」 - 如果你不明白去你的Facebook帳戶>> acouunt設置>>用戶名 – 2013-04-25 04:07:22