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"> 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 양식 :
<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>
데이터 필드를 변화와 시도가 작동하지 않습니다. – mouli