自动完成中的Jquery错误

时间:2017-05-04 14:24:48

标签: javascript jquery json ajax autocomplete

我在自动填充字段上获得了Uncaught TypeError: Cannot use 'in' operator to search for 'length' in。这是代码:

    enable_autocomplete: function() {
    $( 'input.fm-autocomplete:visible' ).each( function() {
        if ( !$( this ).hasClass( 'fm-autocomplete-enabled' ) ) {
            var ac_params = {};
            var $el = $( this );
            var $hidden = $el.siblings( 'input[type=hidden]' ).first();
            ac_params.select = function( e, ui ) {
                e.preventDefault();
                $el.val( ui.item.label );
                $hidden.val( ui.item.value ).trigger( 'change' );
            };
            ac_params.focus = function( e, ui ) {
                e.preventDefault();
                $el.val( ui.item.label );
            }
            if ( $el.data( 'action' ) ) {
                ac_params.source = function( request, response ) {
                    // Check for custom args
                    var custom_args_js_event = $el.data( 'customArgsJsEvent' );
                    var custom_data = '';
                    if ( 'undefined' !== typeof custom_args_js_event && null !== custom_args_js_event ) {
                        var custom_result = $el.triggerHandler( custom_args_js_event );
                        if ( 'undefined' !== typeof custom_result && null !== custom_result ) {
                            custom_data = custom_result;
                        }
                    }

                    $.post( ajaxurl, {
                        action: $el.data( 'action' ),
                        fm_context: $el.data( 'context' ),
                        fm_subcontext: $el.data( 'subcontext' ),
                        fm_autocomplete_search: request.term,
                        fm_search_nonce: fm_search.nonce,
                        fm_custom_args: custom_data
                    }, function( result ) {
                        console.log( result );
                        $.parseJSON( response( result ) );
                    } );
                };

与此错误相关的所有其他问题都提示$.parseJSON,但它对我不起作用。当我输入result时,这是eco的console.log:

[{"label":"Economy Talks","value":1480},{"label":"Economy","value":212},{"label":"Economy motors","value":2038},{"label":"Telecomunica\u00e7\u00f5es","value":402}]

response的Console.log:

function (){return a.apply(b||this,c.concat(e.call(arguments)))}

它找到了正确的建议,但后来我得到Uncaught TypeError: Cannot use 'in' operator to search for 'length' in,我无法选择任何选项。任何想法如何解决这个问题?

0 个答案:

没有答案