jquery-ui autocomplete按Enter键无法使用ajax加载的表单

时间:2017-09-10 14:28:17

标签: jquery ajax asp.net-mvc autocomplete

当我点击搜索按钮时,我有自动完成搜索工作正常,但是当我按下键盘上的Enter并且我无法弄清楚问题出在哪里时它不起作用,它是jquery Ajax!还是HTML!我也试过自动对焦,但它再次无效。任何人都可以指引我朝着正确的方向前进吗?

代码如下所示:

<div style="color:white;" class="form-group  is-empty">
    @Html.TextBox("OrderID", null, new { @class = "form-control", placeholder = "Order nr", @id = "search_term" })

    <span class="material-input"></span>
</div>
<button type="submit" onclick="SearchOrderList(0,$('#search_term').val())" class="btn btn-white btn-round btn-just-icon">
    <i class="material-icons">search</i><div class="ripple-container"></div>
</button>

$("#search_term").autocomplete({
    source: function (request, response) {

        $.ajax({
            url: "/Account/SearchAutoComplete",
            type: "POST",
            dataType: "json",
            data: { term: request.term },
            change: function (event, ui) {

                console.log("blala");
            },
            success: function (data) {
                response($.map(data, function (item) {
                    return { label: item.text, value: item.text };
                }));

            }
        });
    },
});

0 个答案:

没有答案