Gohel Dhaval
Gohel Dhaval

Reputation: 830

how to fire ajax in typeahead when key press

My problem is I am using type ahead for my top search it work but only one time ajax call in key press but I have call every time when I press key my code is below

$.typeahead({
    input: '.js-typeahead-car_v1',
    maxItem: 100,
    order: "asc",
    hint: true,
    source: {
        searchkey: {
            url: {
                type: "POST",
                url: "/search",
                data: {
                    myKey: "muvalue"
                }
            }
        }
    },
    callback: {
        onClick: function (node, a, item, event) {
            $("#topsearchbtn").trigger( "click" );
        },
        onSubmit: function (node, form, item, event) {
            $("#topsearchbtn").trigger( "click" );
        }
    }
});

Upvotes: 0

Views: 376

Answers (1)

Gohel Dhaval
Gohel Dhaval

Reputation: 830

Below code are working fine and also i am used in one of the my project

$.typeahead({
    input: '.js-typeahead-car_v1',
    minLength: 3,
    maxItem: 20,
    order: "asc",
    dynamic: true,
    emptyTemplate: "no result for {{query}}",
    source: {
        searchkey: {
            url: {
                type: "POST",
                url: '/search',
                data: {
                    q: "myqery"
                }
            }
        }
    },
    callback: {
        onClick: function (node, a, item, event) {
            $("#topsearchbtn").trigger( "click" );
        },
        onSubmit: function (node, form, item, event) {
            $("#topsearchbtn").trigger( "click" );
        }

    },
    debug: true
});

Upvotes: 1

Related Questions