我正在使用typeahead插件进行自动完成搜索。我使用了Laravel 5.5,查询生成器,ajax和jquery。当我在姓氏框中键入内容时,屏幕上没有任何反应,控制台返回此错误:
TypeError: b.toLowerCase is not a function.
matcher http://127.0.0.1:8000/js/typeahead.js:1
b http://127.0.0.1:8000/js/typeahead.js:1
grep jQuery
process http://127.0.0.1:8000/js/typeahead.js:1
i jQuery
success http://127.0.0.1:8000/referti:257
jQuery 4
c
fireWith
l
o
这是已实现的代码:
标题:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="{{URL::asset('css/stilelogin_antonio.css')}}">
<link rel="stylesheet" type="text/css" href="{{URL::asset('css/style.css')}}">
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="{{URL::asset('js/typeahead.js')}}" ></script>
表格:
<div class="form-container">
<div class="form-group">
<label for="cognome">Cognome:</label>
<input class="typeahead form-control" type="text" id="cognome" autocomplete="off" placeholder="Cognome"/>
</div>
脚本:
$(document).ready(function () {
_token = $('meta[name="csrf-token"]').attr('content');
$('#cognome').typeahead({
source: function (query, result) {
console.log('-->', query);
$.ajax({
url: "/referti/searchBySurname",
method: "post",
data: {query: query, _token: _token },
dataType: "json",
success: function (data) {
//console.log(data);
result($.map(data, function (item) {
return item;
}));
}
});
}
});
});
控制器:
class RefertiController extends Controller{
public function searchBySurname(Request $request){
$data = $request->get('query');
Log::info('-->' . $data);
$reports = DB::table('PATIENT')
->where('LAST_NAME', 'LIKE', "%$data%")
->get();
Log::info($reports);
return json_encode($reports);
}
}
这是的一部分。日志文件正确生成:
[2019-09-26 13:54:57] local.INFO:
[{"PATIENT_KEY":"19234283CDGIULIANI ","LAST_NAME":"GIULIANI","FIRST_NAME":"ADELE","BIRTHDATE":"1923-04-28","SEX":"F","ETHNICITY":null,"REF_PHYSICIAN":null,"PAT_COMMENT":"ister-ann bil","MENOPAUSE_YEAR":-1},
{"PATIENT_KEY":"19261214BEGIULIANAT","LAST_NAME":"GIULIANATI","FIRST_NAME":"SENICE","BIRTHDATE":"1926-01-20","SEX":"F","ETHNICITY":"W","REF_PHYSICIAN":null,"PAT_COMMENT":"postmenopausa spontanea","MENOPAUSE_YEAR":-1},...
我该怎么做才能解决问题?我哪里错了? 多亏有谁回答!