Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Ajax实时数据库检查_Php_Jquery_Ajax_Xmlhttprequest - Fatal编程技术网

Php Ajax实时数据库检查

Php Ajax实时数据库检查,php,jquery,ajax,xmlhttprequest,Php,Jquery,Ajax,Xmlhttprequest,我正在做一个登记表,它将检查输入的手机号码是否正在使用,就像twitter的用户名检查一样。我的代码看起来很完美,但我不断得到“检查号码可用性”,就像ajax没有发布我的请求一样。请帮忙:-) 下面是相关的ajax代码位 <script type="text/javascript"> $(document).ready(function()//When the dom is ready { $("#cellphone_number").change(function() { //

我正在做一个登记表,它将检查输入的手机号码是否正在使用,就像twitter的用户名检查一样。我的代码看起来很完美,但我不断得到“检查号码可用性”,就像ajax没有发布我的请求一样。请帮忙:-) 下面是相关的ajax代码位

<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>

$(document).ready(function()//当dom就绪时
{
$(“#手机号码”)。更改(功能()
{//如果用户名文本框中有更改
var phonenumber=$(“#手机号码”).val();//获取用户名文本框中的值
if(phonenumber.length==13)//如果长度等于13个字符
{
$(“#可用性_状态”).html('检查号码可用性…');
//在span id=“可用性\u状态”中添加加载映像
$.ajax({//发出ajax请求
类型:“POST”,
url:“../Functions/ajax\u check\u number.php”,//文件名
数据:((“number=”+phonenumber),//数据
成功:功能(服务器响应)
{     
$(“#可用性_状态”).ajaxComplete(函数(事件、请求){
if(server\u response=='0')//if ajax\u check\u username.php返回值“0”
{ 
$(“#可用性状态”).html('Number is Available');
//将此映像添加到id为“availability\u status”的范围中
}  
else if(server_response=='1')//如果返回“1”
{  
$(“#可用性_状态”).html(‘已在使用的编号’);
}  
});
} 
}); 
}
其他的
{
$(“#可用性_状态”).html('数字太短');
//如果用户名仅少于或等于3个字符
}
返回false;
});
});

现在,代码的编辑程度至少达到了我这样的AJAX和Javascript初学者都能理解的程度。这项工作做得很好。添加一些GIF图像以向客户端用户提供“视觉”响应,尤其是在检查数据库时

<script type="text/javascript">
$(document).ready(function()//When the dom is ready
$(document).ready(function()//When the dom is ready
{
$("#cellphone_number").change(function()

{ //if there's a change in the cellphone_number textbox
var phonenumber = $("#cellphone_number").val();//Get the value in the username textbox
if(phonenumber.length == 13)//if the length is equal to 13 characters
{
$("#availability_status").html('< align="absmiddle" >&nbsp;<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:$("#cellphone_number").val()},//data    
dataType: 'json',  
success: function(server_response)
{     
$("#availability_status").ajaxComplete(function(event, request)
{     
if(server_response == '0')//if ajax_check_number.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 number is less than 13 characters only 
}
return false;
});
});
</script>

$(document).ready(function()//当dom就绪时
$(document).ready(function()//当dom就绪时
{
$(“#手机号码”)。更改(功能()
{//如果手机号码文本框有变化
var phonenumber=$(“#手机号码”).val();//获取用户名文本框中的值
if(phonenumber.length==13)//如果长度等于13个字符
{
$(“#可用性_状态”).html(“检查号码可用性…”);
//在span id=“可用性\u状态”中添加加载映像
$.ajax({//发出ajax请求
类型:“POST”,
url:“../Functions/ajax\u check\u number.php”,//文件名
数据:{number:$(“#手机号码”).val()},//数据
数据类型:“json”,
成功:功能(服务器响应)
{     
$(“可用性状态”).ajaxComplete(功能(事件、请求)
{     
if(server\u response=='0')//if ajax\u check\u number.php返回值“0”
{ 
$(“#可用性状态”).html('Number is Available');
//将此映像添加到id为“availability\u status”的范围中
}  
else if(server_response=='1')//如果返回“1”
{  
$(“#可用性_状态”).html(‘已在使用的编号’);
}
});
} 
});
}
其他的
{
$(“#可用性_状态”).html('数字太短');
//如果数字仅少于13个字符
}
返回false;
});
});

$(文档).ready(函数()
{ 
$(“#手机号码”)。更改(功能()
{ 
var phonenumber=$(“#手机号码”).val();
if(phonenumber.length==13)
{ 
$(“#可用性_状态”).html('检查号码可用性…');
$.ajax(
{ 
类型:“POST”,
url:“../Functions/ajax\u check\u number.php”,
数据:{number:phonenumber},
成功:功能(服务器响应)
{ 
如果(服务器\u响应=='0')
{ 
$(“#可用性状态”).html('Number is Available');
} 
else if(服务器\u响应=='1')
{ 
$(“#可用性_状态”).html(‘已在使用的编号’);
} 
} 
}); 
} 
其他的
{ 
$(“#可用性_状态”).html('数字太短');
} 
}); 
}); 

请正确设置代码格式代码都不可靠…我会修复它,但我没有权限…您是否尝试使用Firebug查看您的请求是否已发布?嘿,伙计们,感谢您的努力。成功解决了问题。您只需在AJAX部分添加dataType='json',在该部分中定义url、数据、类型和成功。我的同事德是所有摇摇晃晃,但有人清理它(我是新的)。谢谢。现在我不知道为什么它不能识别国际电话号码格式,例如+254…。必须是加号。希望能解决这个问题,或者有人帮助我。再次感谢。您好,欢迎使用Stack Overflow。当您发布代码来解释它正在做什么,以及为什么它可能会解决这个问题时,这会很有帮助。另外,这问题是一个相当老的问题,已标记为完整。您的答案可能会在新问题上引起更多注意,您可以在主页上查看。
<script type="text/javascript"> 
$(document).ready(function()
{ 
    $("#cellphone_number").change(function() 
    { 
        var phonenumber = $("#cellphone_number").val();
        if(phonenumber.length == 13)
        { 
            $("#availability_status").html('<align="absmiddle"><font color="#00FF33">Checking Number availability...</font>');  
            $.ajax(
            { 
                type: "POST", 
                url: "../Functions/ajax_check_number.php",
                data: {number: phonenumber},
                success: function(server_response) 
                { 
                    if(server_response == '0')
                    { 
                        $("#availability_status").html('<align="absmiddle"> <font color="#00FF33">Number is Available </font> '); 
                    } 
                    else if(server_response == '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>'); 
           } 
            }); 

}); 
</script>