Php 我想在AJAX中使用文本框搜索
您好,我正在尝试找出如何使用我的文本框和AJAX进行实时搜索,然后使用数据库中的数据更新页面。但我希望输出时使用以下标题:Php 我想在AJAX中使用文本框搜索,php,jquery,mysql,ajax,Php,Jquery,Mysql,Ajax,您好,我正在尝试找出如何使用我的文本框和AJAX进行实时搜索,然后使用数据库中的数据更新页面。但我希望输出时使用以下标题: <th>Medewerker</th> <th>Datum overboeking</th> <th>Juliette geinformeerd</th> <th>Boekingsnummer&l
<th>Medewerker</th>
<th>Datum overboeking</th>
<th>Juliette geinformeerd</th>
<th>Boekingsnummer</th>
<th>Land</th>
<th>Huiscode</th>
<th>Aanbieder</th>
<th>Contractvorm</th>
<th>Huursom</th>
<th>Periode van</th>
<th>Periode tot</th>
<th>Distributiekanaal</th>
<th>Naam klant</th>
<th>Reden</th>
<th>Nieuwe boeking</th>
<th>Reden geen nieuwe boeking</th>
<th>Boete aanbieden</th>
<th>Administratie geinformeerd voor inhouding boete</th>
<th>Bedrag van boete</th>
<th>Coulance Happyhome</th>
<th>Opmerking</th>
<th>Id</th>
HTML
<td>
<input type="text" name="naam_klant" size="20" id="naam_klant" onkeyup="lookup(this.value);" onblur="fill();" >
<div class="suggestionsBox" id="suggestions" style="display: none;">
<div class="suggestionList" id="autoSuggestionsList">
</div>
</div>
</td>
AJAX
<script>
function makeTable(data) {
var tbl_body = "";
$.each(data, function() {
var tbl_row = "";
$.each(this, function(k , v) {
tbl_row += "<td>"+v+"</td>";
})
tbl_body += "<tr>"+tbl_row+"</tr>";
})
return tbl_body;
}
function getEmployeeFilterOptions(){
var opts = [];
$checkboxes.each(function(){
if(this.checked){
opts.push(this.name);
}
});
return opts;
}
function getEmployeeFilterOptions2(){
var opts = [];
$onchange.each(function(){
if(this.checked){
opts.push(this.name);
}
});
return opts;
}
function updateEmployees(opts){
$.ajax({
type: "POST",
url: "submit.php",
dataType : 'json',
cache: false,
data: {filterOpts: opts},
success: function(records){
$('#employees tbody').html(makeTable(records));
}
});
}
var $checkboxes = $("input:checkbox");
$checkboxes.on("change", function(){
var opts = getEmployeeFilterOptions();
updateEmployees(opts);
});
updateEmployees();
</script>
函数makeTable(数据){
var tbl_body=“”;
$.each(数据,函数(){
var tbl_row=“”;
$。每个(此,函数(k,v){
tbl_行+=“+v+”;
})
tbl_正文+=“”+tbl_行+“”;
})
返回tbl_体;
}
函数getEmployeeFilterOptions(){
var opts=[];
$复选框。每个(函数(){
如果(选中此项){
opts.push(这个名称);
}
});
返回选项;
}
函数getEmployeeFilterOptions 2(){
var opts=[];
$onchange.each(函数(){
如果(选中此项){
opts.push(这个名称);
}
});
返回选项;
}
功能更新员工(opts){
$.ajax({
类型:“POST”,
url:“submit.php”,
数据类型:“json”,
cache:false,
数据:{filterOpts:opts},
成功:功能(记录){
$('#employees tbody').html(makeTable(records));
}
});
}
var$复选框=$(“输入:复选框”);
$checkbox.on(“更改”,函数(){
var opts=getEmployeeFilterOptions();
更新员工(opts);
});
更新员工();
但是我被困在这里做什么,代码不工作。我建议首先修复返回结果的php脚本 一个明显的错误是您在if子句中的语句:
if (in_array("naam_klant", $opts)){
"naam_klant = '{$opts['naam_klant']}%' ";
}
我认为您正在尝试设置where变量,所以它应该是这样的:
if (in_array("naam_klant", $opts)){
$where = " WHERE naam_klant = '{$opts['naam_klant']}%' ";
}
你的PHP代码至少能工作吗?除了if(in_数组(“naam_klant”,“opts”){“naam_klant='{$opts['naam_klant']}%'”;})和如果你使用'if(in_数组(“naam_klant”,“naam_klant”,“opts”)!==false{“naam_klant='{$opts['naam_klant']}%'”;}`
if (in_array("naam_klant", $opts)){
$where = " WHERE naam_klant = '{$opts['naam_klant']}%' ";
}