I have the following ajax code for a select input:
$("#franchise").change(function() {
//alert( $( "#franchise" ).val() );
var f = $( "#franchise" ).val();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: 'POST',
url : "{{ route('ajax.series') }}",
data : ({franchise : f}),
dataType: 'JSON',
success: function(response) {
$("#series").html('');
$("#series").append(response);
}
});
});
And I also the following route:
Route::post('ajax/series', 'AjaxController@series')->name('ajax.series');
I have the following code in AjaxController:
public function series(Request $request)
{
$id = $request->input('franchise');//I get the id data from select input
$series = Serie::where('franchise_id',$id)->get();
return view('ajax.series', ['series' => $series]);
}
But when I do the select event nothing happens.
I know that the change
event works because I check it only with an alert
so the problem may be the ajax. What's the problem?