I'm working on autocomplete search with typeahead plugin. I used Laravel 5.5, query builder, ajax and jquery. When I type in the surname box nothing happens on screen and the console returns this error:
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
This is the implemented code:
-
Header:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href=""> <link rel="stylesheet" type="text/css" href=""> <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script> <script src="" ></script>
-
Form:
<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>
-
Script:
$(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; })); } }); } }); });
-
Controller:
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); } }
-
This is a part of what the . log file produces, correctly:
[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},...
What can I do to solve the problem? Where am I wrong? Thanks to whoever answers!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire