1

I am trying to show Autocomplete results in a specific div #search-result. So far I am able to send request successfully and get Json array in return.

But I am having issues to show the results in a div.

My Code:

<input type="search" id="main_search" value="" placeholder="type keyword(s) here" />    
<div id="search-result" class="search-resutls"></div>

<script>   
        (function ($) {
                $.widget("app.autocomplete", $.ui.autocomplete, {

                    options: {
                        suggest: false
                    },
                    _suggest: function (items) {

                        if ($.isFunction(this.options.suggest)) {
                            return this.options.suggest(items);
                        }

                        this._super(items);
                    },
                    _close: function (e) {
                        if ($.isFunction(this.options.suggest)) {
                            this.options.suggest([]);
                            return this._trigger("close", e);
                        }
                        this._super(e)
                    }
                });

                $(function () {
                    $("#main_search").autocomplete({
                        source: "/Search/",
                        minLength: 1,
                        response: function (e, t) {
                            if (0 === t.content.length) {
                                var a = new Object;
                                t.content.push(a)
                            }
                        },
                        select: function (e, t) {
                            return $("#main_search").val(t.item.title),
                                $("#main_search-query").val(t.item.query)
                        },
                        suggest: function (e, t) {
                            var $div = $(".search-resutls").empty();
                            $.each(t, function () {
                                $("<a/>").attr("href", t.query).text(t.title).appendTo($div);
                            });
                        }
                    })
                });
            })(jQuery);
</script>

Please help me to solve this. Thanks

aadi1295
  • 982
  • 3
  • 19
  • 47

0 Answers0