Feroz Ahmed
Feroz Ahmed

Reputation: 1135

js autocomplete ajax PHP response

I'm not getting response on autocomplete hinds.

There is my jQuery code

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

And i'm getting this response from the AJAX but it's not showing on autocomplete hinds

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

Upvotes: 1

Views: 215

Answers (1)

Suraj Gavhane
Suraj Gavhane

Reputation: 176

replace your code with following code

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

Upvotes: 2

Related Questions