我正在尝试使用 AJAX 自动完成功能,但在让两种语言协同工作时遇到了一些问题。
当我只用 1 个 $_POST 替换所有 issets 时,下面的代码段将起作用,但是通过添加另一个 $_POST 我在第 5 行得到一个错误。
<?php
require_once '../Configuration.php';
if (isset($_POST['search_term'] . $_POST['postcode']) == true && empty ($_POST['search_term'] . $_POST['postcode']) == false) {
$search_term = mysql_real_escape_string($_POST['search_term'] . $_POST['postcode']);
$query = mysql_query("SELECT `customer_name`,`postcode` FROM `Customers` WHERE `customer_name` LIKE '$search_term%' ");
while(($row = mysql_fetch_assoc($query)) !== false) {
//loop
echo '<li>',$row['customer_name'] . $row['postcode'] '</li>';
}
}
?>
任何关于为什么抛出此错误的建议将不胜感激。谢谢。
我知道我应该使用 mysqli,我只是想先了解逻辑:)
JS:
Primary.js:
$(document).ready(function() {
$('.autosuggest').keyup(function() {
var search_term = $(this).attr('value');
var postcode = $_GET['postcode'];
//alert(search_term); takes what is typed in the input and alerts it
$.post('ajax/search.php', {search_term:search_term, postcode:postcode}, function (data) {
$('.result').html(data);
$('.result li').click(function() {
var result_value = $(this).text();
$('.autosuggest').attr('value', result_value);
$('.result').html('');
});
});
});
});