我正在使用 ajax 進行實時搜索,但問題是它只顯示了一個結果
當我使用 .html() 但當我使用 append() 時它作業但我寫的每個單詞都復制結果,
這是我的代碼:
在控制器中,
$patient = Patient::select('id', 'avatar')
->where('phone_number', 'like', '%' . $search_query . '%')
->orWhere('first_name', 'like', '%' . $search_query . '%')
->limit(15)
->get();
return $patient;
刀片中的ajax代碼
$("#search-eng").keyup(function() {
let search_query = $(this).val();
if (search_query != "") {
$.ajax({
url: '{{ url('/appointment/calander_patient_search') }}/'
search_query,
type: "GET",
dataType: "json",
success: function(data) {
$("#search-eng-show-list").show();
if (data !== "") {
$.each(data, function(key, value) {
$('#search-eng-show-list').html(
'<a data-id="' value.id '"' value.second_name '</a>');
});
}
if (data == "") {
$('#search-eng-show-list').html(
'<a><i "></i>No Record</a>'
);
}
},
});
} else {
$("#search-eng-show-list").empty();
$("#search-eng-show-list").hide();;
}
});
uj5u.com熱心網友回復:
是的,您在回圈陳述句中設定了內容,因此它只會獲取最后一個內容。
您可以使用一些緩沖區變數:
if (data !== "") {
var html = '';
$.each(data, function(key, value) {
html = '<a data-id="' value.id '"' value.second_name '</a>');
}
$('#search-eng-show-list').html(html);
// ....
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/314708.html
標籤:javascript php 查询 阿贾克斯 拉拉维尔
