【问题标题】:js autocomplete ajax PHP responsejs自动完成ajax PHP响应
【发布时间】:2017-03-03 01:08:12
【问题描述】:

我没有收到关于自动完成功能的回复。

这是我的 jQuery 代码

jQuery( ".newtag_new" ).autocomplete({
    minLength: 0,
    source: function( request, response ) {
        jQuery.ajax({
            type: 'GET',
            url: clipper_params.ajax_url,
            dataType: "json",
            data: {
                action : "ajax-tag-search-front-new",
                term : request.term
            }
        });
    },
    focus: function( event, ui ) {
        jQuery( ".newtag_new" ).val( ui.item.label );
        return false;
    },
    select: function( event, ui ) {
        window.location.replace("http://domain.com");
        return false;
    }
})
.autocomplete( "instance" )._renderItem = function( ul, item ) {
    return jQuery( "<li>" )
    .append( "<div>" + item.label + "<br>" + item.desc + "</div>" )
    .appendTo( ul );
};

我从 AJAX 收到了这个响应,但它没有显示在自动完成后

[{"value":"jquery","label":"jQuery","desc":"the write less, do more, JavaScript library","icon":"jquery_32x32.png"}]

【问题讨论】:

    标签: javascript jquery ajax autocomplete


    【解决方案1】:

    用下面的代码替换你的代码

    source: function (request, response) {
        $.getJSON(clipper_params.ajax_url, {
            action : "ajax-tag-search-front-new",
            term : request.term
        },response);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-07
      • 2010-10-14
      • 1970-01-01
      • 1970-01-01
      • 2012-07-31
      • 1970-01-01
      • 2015-04-01
      • 1970-01-01
      相关资源
      最近更新 更多