我尝试了这一系列代码但它并不适合我。每次我搜索一些东西它都会给我"结果无法加载" 我错过了什么吗?谢谢你提前。
phpfile.php
define (DB_USER, "root");
define (DB_PASSWORD, "");
define (DB_DATABASE, "db");
define (DB_HOST, "localhost");
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
$sql = "SELECT customer_information.CUS_CODE_MX, customer_information.CUS_NAME_MX FROM customer_information WHERE CUS_NAME_MX LIKE '%".$_GET['q']."%'
LIMIT 10";
$result = $mysqli->query($sql);
$json = [];
while($row = $result->fetch_assoc()){
$json[] = ['id'=>$row['CUS_CODE_MX'], 'text'=>$row['CUS_NAME_MX']];
}
echo json_encode($json);
的index.php
<select name="CUSTOMER_ID" id="CUSTOMER_IDGET1" required style="width:100%" class="CUSTOMER_IDGET1 form-control"></select>
function.js
$('.CUSTOMER_IDGET1').select2({
placeholder: 'Select an Customer',
ajax: {
url: 'ajaxpro.php',
dataType: 'jsonp',
delay: 250,
processResults: function (data) {
return {
results: data
};
},
cache: true
}
});