【问题标题】:Autocomplete is not working in Express.js code自动完成在 Express.js 代码中不起作用
【发布时间】:2018-09-17 18:08:40
【问题描述】:

【问题讨论】:

  • 您能否复制您的代码并(编辑)将其粘贴到问题中。

标签: javascript node.js ajax express npm


【解决方案1】:

如下更新您的代码:

$(".autocomplete").autocomplete({
    source: function (request, response) {
        $.ajax({
            url: "/get_vehicle",
            method: "get",
            data: {
                term: request.term
            },
            success: function (data) {
                if (data.length) {
                    response($.map(data, function (item) {
                        return {
                            label: item.model,
                            value: item.model
                        };
                    }));
                }
            }
        });
    },
});

router.get('/get_vehicle', function (req, res) {
  vehicle.find(function (err, result) {
    res.status(200).send(result);
  })
})

【讨论】:

    【解决方案2】:

    你缺少一个'/'

    在 index.js 中将 'get_vehicle' 更改为 '/get_vehicle'

    【讨论】:

      猜你喜欢
      • 2016-08-31
      • 2015-05-27
      • 2011-12-26
      • 1970-01-01
      • 2012-04-10
      • 1970-01-01
      • 2019-05-26
      • 2021-08-18
      • 2020-08-29
      相关资源
      最近更新 更多