I tried to call a data engineer based on their service point using ajax, but the result of the ajax is [object Object], where is my mistake?
this is my script
function engineer(url, id, name) {
// send ajax request to get the cities of the selected province and append to the select tag
$.ajax({
url: url,
type: 'GET',
data: {
id: id
},
success: function(data) {
$('#' + name).empty();
$('#' + name).append('<option>- Choose Option -</option>');
$.each(data, function(key, value) {
$('#' + name).append('<option value="' + key + '">' + value + '</option>');
});
}
});
}
$(function() {
$('#servp').on('change', function() {
engineer('{{ route('engineer') }}', $(this).val(), 'engineer');
});
});
and this my controller
return User::all()->where('depart', 6)->where('service_point', $request->id);
and this one is the routes
Route::get('engineer', [TicketController::class,'engineer'])->name('engineer');
I want when selecting a service point an engineer appears who is only at that service point