MySQL 테이블에서 데이터를 검색하고 검색하려고합니다. 검색 키워드를 얻기 위해 두 개의 텍스트 필드를 사용했습니다. 나는 이것을 위해 jquery ajax를 사용했다. 처음으로 검색을 위해 위치 만 사용했습니다. 그런 다음 작동합니다. 두 텍스트 필드를 모두 사용하면 효과가 없습니다. 그렇다면 나는 항상 no data
입니다.jquery ajax에서 두 개의 텍스트 필드 데이터를 사용하는 검색 기능
var loca=$('#location').val();
var cato=$('#catogary').val();
는 또한 dataType
하지 DataType
를 사용할
<div class="container">
<form action="search.php" method="post">
<input type="text" id="location" name="location">
<input type="text" id="catogary" name="catogary">
<script>
$('#location,#catogary').keyup(function() {
var loca=$(this).val();
var cato=$(this).val();
if(loca!='' || cato!=''){
$.ajax({
url:"search.php",
method:"POST",
data:{searc:loca,cato:cato},
DataType:"text",
success:function (data) {
$('#result').html(data);
}
});
}
else{
$('#result').html('');
}
});
</script>
</form>
<div id="result"></div>
</div>
PHP 코드
<?php
$conn=mysqli_connect("localhost","root","","internship");
$output='';
$sql="select * from vacancy where location like '%".$_POST["searc"]."%'
and catogary like '%".$_POST["cato"]."%'";
$res=mysqli_query($conn,$sql);
if(mysqli_num_rows($res)>0){
while($row=mysqli_fetch_assoc($res)){
?>
<div class="bs-calltoaction bs-calltoaction-primary">
<div class="row">
<div class="col-md-9 cta-contents">
<h1 class="cta-title">Its a Call To Action</h1>
<div class="cta-desc">
<input type="text" value='<?= $row['catogary'];?>' readonly style="width: 75%"><br><br>
<input type="text" value='<?= $row['company_name'];?>' readonly style="width: 75%"><br><br>
<input type="text" value='<?= $row['location'];?>' readonly style="width: 75%"><br><br>
<input type="text" value='<?= $row['qulification'];?>' readonly style="width: 75%"><br><br>
<input type="text" value='<?= $row['catogary'];?>' readonly style="width: 75%"><br><br>
<input type="text" value='<?= $row['indate'];?>' readonly style="width: 37.5%">
<input type="text" value='<?= $row['expdate'];?>' readonly style="width: 37.5%">
</div>
</div>
<div class="col-md-3 cta-button">
<a class="btn btn-primary btn-large"
href="#myModal" data-toggle="modal">Apply for job</a>
</div>
</div>
</div>
<?php
}
}
else{
echo 'no data';
}
?>
값 얻기 위해, 살균 및 및 유효성을 검사 한 후 사용한다. –
ajax 호출에서 두 필드의 값이 아니라 loca와 cato를 같은 것으로 설정합니다. –