I tried this series of code but it doesn't work for me. every time i searched some thing it will give me "The result could not be loaded" did my missed something here ? Thankyou in advance.
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
}
});