结果无法加载select2 ajax json

时间:2017-06-29 06:52:24

标签: php jquery json ajax

  

我尝试了这一系列代码但它并不适合我。每次我搜索一些东西它都会给我"结果无法加载"   我错过了什么吗?谢谢你提前。

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
        }
      });

0 个答案:

没有答案