0
我正在使用AJAX
和jQuery
製作一個自動完成文本框。這是我的客戶端AJAX代碼。PHP在處理ajax請求時未定義的索引
$(document).ready(function(){
$('#tagtext').autocomplete({
source: function(request, response) {
$.ajax({
url : 'ajax.php',
dataType: "json",
data: {
name_startsWith: request.term,
type: 'country'
},
success: function(data) {
response($.map(data, function(item) {
return {
label: item,
value: item
}
}));
}
});
},
autoFocus: true,
minLength: 0
});
});
這裏是我的服務器端ajax.php
代碼:
<?php
require_once 'db_const.php';
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if(isset($_GET['type']) AND $_GET['type'] == 'country'){
$result = $mysqli->query("SELECT tagname FROM tagtable where tagname LIKE '".strtoupper($_GET['name_startsWith'])."%'");
$data = array();
while ($row = mysqli_fetch_array($result)) {
array_push($data, $row['tagname']);
//echo "Hello " .$row['tagname'];
}
echo json_encode($data);
} else {
echo "hello";
}
?>
的錯誤,我沒有得到一個值作爲國家在$_GET['type']
(即$ _GET沒有設置),它是未來如果條件爲並且執行其他分支。
任何人都可以幫助我如何獲得"$_GET['type'] == country"
?