Typeahead和Bloodhound post请求在Laravel 5中不起作用

时间:2017-10-14 09:58:53

标签: php jquery laravel-5 typeahead bloodhound

这是我的HTML代码:

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

这是我的Jquery猎犬和先行代码:

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');
  }

我想要实现的是我想将post请求发送到控制器并接收JSON作为响应。我遇到问题我不知道我的代码出错了:(

1 个答案:

答案 0 :(得分:0)

$request->get()无法读取JSON发布的数据。您应该使用$request->input()

见(拒绝)PR:https://github.com/laravel/framework/pull/13566#issue-154985037