dongpao1905 2017-01-14 20:26
浏览 45

选择ajax内容

I can not cope with the solution of this problem. The content of the problem:

select2.full.js:4025 Uncaught TypeError: Cannot read property 'slice' of undefined
at DecoratedClass.HidePlaceholder.removePlaceholder (select2.full.js:4025)
at DecoratedClass.removePlaceholder (select2.full.js:594)
at DecoratedClass.HidePlaceholder.append (select2.full.js:4008)
at DecoratedClass.append (select2.full.js:594)
at Select2. (select2.full.js:1025)
at Select2.Observable.invoke (select2.full.js:651)
at Select2.Observable.trigger (select2.full.js:641)
at Select2.trigger (select2.full.js:5489)
at select2.full.js:5348
at Object.options.transport.self.trigger.message (select2.full.js:3482)

What am I doing wrong?

$(document).ready(function(){

$('#select2').select2({
               minimumInputLength:1,
               width: '300px',
               placeholder:"Select Parent Menu",
                ajax: {
                    type:"get",
                    url: "../test/inc/ajax/ajaxlux.php",
                    dataType: 'json',
                    quietMillis: 100,
                    data: function(params) {
                        return {
                            query: params.term, //search term
                            page_limit: 10 // page size 
                            
                        };
                        console.log(data);
                    },

        results: function(data) {
                        var newData = [];
                        for ( var i = 0; i < data.length; i++ ) {
                            newData.push({
                                id: item.FormID  //id part present in data
                                , text: item.FormName  //string to be displayed
                            });
                        }
                        return { results: newData };
                    },

                }
            });
  });
<select id="select2">

</select>';

And ajaxlux.php:

    $sql = "
SELECT ".$prefix."product.product_id,".$prefix."product.product_name
FROM ".$prefix."product 
WHERE ".$prefix."product.product_name LIKE '%".$_GET['query']."%'
AND ".$prefix."product.product_active = '1'
ORDER BY product_name ASC  LIMIT 10 " ;

    $result= mysqli_query($link,$sql) or die(mysqli_error());       

     $json = [];
    while($row = mysqli_fetch_assoc($result)){   
         $json[] = array (
            'FormID' => $row['product_id'],
            'FormName' => $row['product_name'],

        );
    }
    echo json_encode($json, JSON_UNESCAPED_UNICODE ); 

}

I looked through many sites on the internet and the same code as my work for someone else.

</div>
  • 写回答

1条回答 默认 最新

  • duai0935 2017-01-15 02:14
    关注

    this is how I had to set up mine to get it to work:

            $('#select2').select2({
                minimumInputLength:1,
                width: '300px',
                placeholder:"Select Parent Menu",
                ajax: {
                    type:"get",
                    url: "../test/inc/ajax/ajaxlux.php",
                    dataType: 'json',
                    quietMillis: 100,
                    data: function(params) {
                        return {
                            query: params.term, //search term
                            page_limit: 10 // page size 
    
                        };
                        console.log(data);
                    },
    
                    processResults:  function(data) {
                        newData =    $.map(data, function (ind, item ) {
                            item.id = item.FormID;
                            item.text = item.FormName;
                            return item;
                        } );
    
                        return { results: newData };
                    },
    
                }
            });
    
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改