我想使用被標記爲工作的代碼,我沒有得到任何結果,它只是空的。注意:如果單獨運行,MySQL會返回結果,所以它不是一個SQL的東西。有什麼建議麼?使用JQuery自動完成與PHP/MySQL不工作
HTML:
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
Name: <input id="hint" />
<script type="text/javascript">
$("#hint").autocomplete({
source: function (request, response) {
$.ajax({
url: "getMedicineNames.php",
dataType: "jsonp",
data: {
name: request
},
success: function (data) {
response(data);
}
});
},
minLength: 3
});
</script>
</body>
PHP:
require 'connect.inc.php';
$mysql = mysqli_connect("$db_host", "$db_username", "$db_pass", "$db_name");
$name = $_POST['name'];
if ($name != "") {
$sql = "SELECT MedicineName FROM medicinetypes WHERE MedicineNAme LIKE '%$name%'";
echo json_encode(mysqli_fetch_all(mysqli_query($mysql, $sql), MYSQLI_ASSOC));
}
正確此行'數據類型: 「JSON」,'不是'數據類型: 「JSONP」,' –
還包括'鍵入:「POST」,' –
仍然沒有.. – Constantine