【问题标题】:Typeahead and bloodhound post request not working in Laravel 5Typeahead 和 Bloodhound 发布请求在 Laravel 5 中不起作用
【发布时间】:2017-10-14 09:58:52
【问题描述】:

这是我的 HTML 代码:

<input autocomplete="off" type="text" id="chiefComplaintInput" name="chiefComplaintInp" class="typeahead-chiefcomplaint form-control input-circle-right" placeholder="Chief Complaints">

这是我的 Jquery Bloodhound 和预输入代码:

var chiefComplaints = new Bloodhound({
    datumTokenizer: function(resp) {
        return Bloodhound.tokenizers.whitespace(resp.value);
    },
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    remote: {
        wildcard: '%QUERY',
        url: "/opd/searchChiefComplaints/",
            transform: function(response) {
                return $.map(response, function(restaurant) {
                    return { value: restaurant.name };
                });
            }
        }
});

$('input#chiefComplaintInput').typeahead({
    hint: false,
    highlight: true,
    minLength: 2,
    limit: 10
},
{
    name: 'chiefComplaints',
    display: 'value',
    source: chiefComplaints,
    templates: {
            header: '<h4 class="dropdown">Restaurants</h4>'
    }   
});

这是我已经定义的路线:

Route::get('opd/searchChiefComplaints/{queryParam}', 'OpdController@searchChiefComplaints');

这是控制器代码:

public function searchChiefComplaints(Request $request)
  {
    // return Response::json($request->get('queryParam'));
    return $request->get('queryParam');
  }

我想要实现的是我想向控制器发送发布请求并接收 JSON 作为响应。但是我在实现它时遇到问题我不知道我的代码哪里出错了:(

【问题讨论】:

  • 在谷歌浏览器的“网络”标签中使用检查来分析您对后端的请求。你可以在响应部分看到一些信息。您还可以分析 laravel 文件夹中的日志文件,看看有什么问题。
  • Nopes 试过了都没有反应

标签: php jquery laravel-5 typeahead bloodhound


【解决方案1】:

$request-&gt;get() 无法读取 JSON 发布的数据。你应该使用$request-&gt;input()。

看到这个(拒绝)PR:https://github.com/laravel/framework/pull/13566#issue-154985037

【讨论】:

    猜你喜欢
    • 2015-11-13
    • 2014-03-16
    • 2018-10-06
    • 2021-11-17
    • 2019-01-27
    • 1970-01-01
    • 1970-01-01
    • 2021-06-18
    • 2017-11-15
    相关资源
    最近更新 更多