Ajax Typeahead

https://github.com/pwarelis/Ajax-Typeahead

$("#ajax-typeahead").typeahead({
    ajax: {
        url: "/path/to/source",
        timeout: 500,
        displayField: "name",
        triggerLength: 1,
        method: "get",
        loadingClass: "loading-circle",
        preDispatch: function (query) {
            showLoadingMask(true);
            return {
                search: query,
                otherParam: 123
            }
        },
        preProcess: function (data) {
            showLoadingMask(false);
            if (data.success === false) {
                // Hide the list, there was some error
                return false;
            }
            // We good!
            return data.mylist;
        }
    }
});

你可能感兴趣的:(Ajax)