2017-11-16 45 views
0

これはデータベースAJAXからデータをフェッチするコードです。テーブル名と構文をチェックしていますが、データを取得できない問題があります。jsファイルからデータを取得できません

ファイル名::

<?php 


    $dbhandle = mysql_connect('localhost', 'root', 'root') or die("Opps some thing went wrong"); 
    mysql_select_db('db_new', $dbhandle) or die("Opps some thing went wrong"); 

    if(isset($_POST['uname']))//If a name has been submitted 
    { 
    $uname= mysql_real_escape_string($_POST['uname']);//Some clean up :) 

    $check_for_uname = mysql_query("SELECT uname FROM `db_new`.`operators` WHERE uname='$uname'"); 
    //Query to check if uname is available or not 

    if(mysql_num_rows($check_for_uname)) 
    { 
    echo '1';//If there is a record match in the Database - Not Available 
    } 
    else 
    { 
    echo '0';//No Record Found - uname is available 
    } 

    } 

    mysql_close($dbhandle); 
    ?> 

このajax_check_uname.phpは私がデータ検証のための上記のファイルを呼び出すスクリプトコードです。

<script type="text/javascript"> 
    $(document).ready(function() //When the dom is ready 
    { 
    $("#uname").change(function() 
    { //if theres a change in the uname textbox 

    var uname = $("#uname").val(); //Get the value in the uname textbox 
    //var re = ^([\w-]+(?:\.[\w-]+)*)\$; 
    if(uname) //if the length greater than 5 characters 
    { 
    $("#availability_status").html('<img src="/ahs/images/loader.gif" align="absmiddle">&nbsp;Checking availability...'); 
    //Add a loading image in the span id="availability_status" 

    $.ajax({ //Make the Ajax Request 
     type: "POST", 
     url: "/abc/app/views/ControlPanelViews/forms/ajax_check_uname.php", //file name 
     data: "uname="+ uname, //data 
     //data: {uname: value}, 
     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('<img src="/abc/images/available.png" align="absmiddle"> <font color="Green"> Available </font> '); 
     //add this image to the span with id "availability_status" 
     } 
     else if(server_response == '1') //if it returns "1" 
     { 
     $("#availability_status").html('<img src="/abc/images/not_available.png" align="absmiddle"> <font color="red">Not Available </font>'); 
     } 
     }); 
     } 
     }); 
    } 

    else 
    { 

    $("#availability_status").html('<label></label>'); 
    //if in case the uname is less than or equal 6 characters only 
    } 


    return false; 
    }); 

    }); 
</script> 

以下のデータを表示するためのHTMLフォーム・コードです。

HTMLのFORM:

<div class="form-group"> 
<label class="control-label col-md-3">Username</label> 
<div class="col-md-9"> 
<input type="text" name="uname" id="uname" class="form-control" placeholder="name" type="text"> 
<span id="availability_status"></span> 
</div></div> 

答えて

0
<script type="text/javascript"> 
    $(document).ready(function() //When the dom is ready 
    { 
    $("#uname").change(function() 
    { //if theres a change in the uname textbox 

    var uname = $("#uname").val(); //Get the value in the uname textbox 
    //var re = ^([\w-]+(?:\.[\w-]+)*)\$; 
    if(uname) //if the length greater than 5 characters 
    { 
    $("#availability_status").html('<img src="/ahs/images/loader.gif" align="absmiddle">&nbsp;Checking availability...'); 
    //Add a loading image in the span id="availability_status" 

    $.ajax({ //Make the Ajax Request 
     type: "POST", 
     url: "/abc/app/views/ControlPanelViews/forms/ajax_check_uname.php", //file name 
     data: {uname: uname}, //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('<img src="/abc/images/available.png" align="absmiddle"> <font color="Green"> Available </font> '); 
     //add this image to the span with id "availability_status" 
     } 
     else if(server_response == '1') //if it returns "1" 
     { 
     $("#availability_status").html('<img src="/abc/images/not_available.png" align="absmiddle"> <font color="red">Not Available </font>'); 
     } 
     }); 
     } 
     }); 
    } 

    else 
    { 

    $("#availability_status").html('<label></label>'); 
    //if in case the uname is less than or equal 6 characters only 
    } 


    return false; 
    }); 

    }); 
</script> 
+0

データフィールドを変更してみました動作していません。 – mouli

関連する問題