Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 预打字格式源_Javascript_Jquery_Ajax_Typeahead - Fatal编程技术网

Javascript 预打字格式源

Javascript 预打字格式源,javascript,jquery,ajax,typeahead,Javascript,Jquery,Ajax,Typeahead,我正试着用打字机。我正在使用AJAX获取我的源代码: $(document).ready(function() { $('input.typeahead').typeahead( { hint: true, highlight: true, minLength: 1 }, {

我正试着用打字机。我正在使用AJAX获取我的源代码:

$(document).ready(function() {
        $('input.typeahead').typeahead( 
        {
            hint: true,
            highlight: true,
            minLength: 1
        },
        {                              
            source: function(query, process) {
                jQuery.ajax({
                    url: 'suggestion.php',
                    dataType: "json",
                    data: {
                        type: 'abc'
                    },  
                    success: function(data) {
                        suggestion = [];
                        for(var i in data)
                        {
                            suggestion.push(data[i]);
                        }
                        console.log(data);
                    }
                });
                process(suggestion);
                return suggestion;
            }
        });
    });
但结果是:

但当我看到日志时:

我有一个字符串数组

控制台消息如下:

我可以看到在第一次键入字符时出现错误,但这只是第一次。一直以来,我都没有定义X5

怎么了?我猜是格式,但我主要是从堆栈中尝试,没有结果错误。我的Php代码返回一个json_encode$数组!这是我第一次使用Ajax和Typeahead


对不起,我的英语太差了。

我想这个建议应该是这样的:

[{ "value": "CBOXXX" }, { "value": "CBAXXX" }]

这取决于数据是什么,但我想说的是建议。push{value:data[i]}工作正常。热烈拥抱,泰