我正在製作一個註冊表,它將檢查輸入的手機號碼是否正在使用,就像在twitter的用戶名檢查中一樣。我的代碼看起來很完美,但我一直在'檢查號碼可用性',就像ajax沒有發送我的請求。幫助請:-) 這裏是有關Ajax代碼位Ajax Live數據庫檢查
<script type="text/javascript">
$(document).ready(function()//When the dom is ready
{
$("#cellphone_number").change(function()
{ //if theres a change in the username textbox
var phonenumber = $("#cellphone_number").val();//Get the value in the username textbox
if(phonenumber.length == 13)//if the lenght equal to 13 characters
{
$("#availability_status").html('<align="absmiddle"><font color="#00FF33">Checking Number availability...</font>');
//Add a loading image in the span id="availability_status"
$.ajax({ //Make the Ajax Request
type: "POST",
url: "../Functions/ajax_check_number.php", //file name
data: ("number="+phonenumber), //data
success: function(server_response)
{
$("#availability_status").ajaxComplete(function(event, request){
if(server_response == '0')//if ajax_check_username.php return value "0"
{
$("#availability_status").html('<align="absmiddle"> <font color="#00FF33">Number is Available </font> ');
//add this image to the span with id "availability_status"
}
else if(server_response == '1')//if it returns "1"
{
$("#availability_status").html('<align="absmiddle"> <font color="#FF0000">Number already in use</font>');
}
});
}
});
}
else
{
$("#availability_status").html('<font color="#FF0000">Number too short</font>');
//if in case the username is less than or equal 3 characters only
}
return false;
});
});
</script>
請格式化代碼正確 – cambraca 2010-11-09 17:37:35
的代碼是所有靠不住的......我會修復它,但我沒有權限... – 2010-11-09 17:37:48
您是否嘗試過使用Firebug,看看你的請求被貼? – 2010-11-09 18:24:31