Hi, I'm biginner in ajax code,
How can I use ajax code to select doctors list from database, to print them in my page, using the selected field in other select component(doctors in the selected establishment).
I wrote this code, but it doesn't work, because it doesn't accept the data for the controller's parameter method:
<script>
$("document").ready(function(){
$("#establishment_id").change(function(){
var est = document.getElementById('establishment_id');
// var users = SecretaryRdvController::user( $(this).val());
$.ajax({
url: '{{ URL::action('SecretaryRdvController@create') }}',
type: 'POST',
dateType: 'json',
data : 'establishment=' + est,
success: function(json){
/* $.each(json, function(users, user) { // pour chaque noeud JSON
// on ajoute l option dans la liste
$('.user_id').append('<option value="'+ user.id +'">'+ user.name +'</option>');
});*/
console.log(json)
}
})
});
});
</script>
and this is the controller's method :
/**
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function user($id)
{
$users = DB::table('users')
->join('user_has_establishment', 'users.id', '=', 'user_has_establishment.user_id')
->join('establishment', 'establishment.id', '=', 'user_has_establishment.establishment_id')
->where('establishment.id', '=', $id)
->select( 'users.*')
->get();
$establishments = Establishment::all();
$patients = Patient::all();
return view('backoffice.secretary.rdv.create')->with('establishments', $establishments)
->with('patients', $patients)->with('users', $users);
}