Reputation: 151
I'm trying to create a dependent select using ajax, here is my JS
$("#make").change(function(){
$.ajax({
url: "{{ url('chauffeur/ajax_vehicle_model') }}?make=" + $(this).val(),
method: 'GET',
success: function(data) {
$('#model').html(data.html);
}
});
});
My routing looks like this
Route::group(['middleware' => ['auth'], 'prefix' => 'admin', 'as' => 'admin.'], function () {
Route::get('chauffeur/ajax_vehicle_model','Admin\ChauffeurController@get_vehicle_model');
});
And in my controller I have this
public function get_vehicle_model(Request $request)
{
....
}
But I get a 404 error, any idea what I'm doing wrong here?
Upvotes: 1
Views: 263
Reputation: 1081
As you see, you have an argument in your route group prefix
, with the value admin
.
This prefixes your routes inside that route group with admin
. This way, your url in JS should look like:
url(“admin/chauffeur/ajax_vehicle_model”)
Upvotes: 1
Reputation: 5582
Try to change your route like this
routing file
Route::get('chauffeur/ajax_vehicle_model', ['as'=> 'chauffeur.ajax.vehicle', 'uses' => 'Admin\ChauffeurController@get_vehicle_model']);
Now your js code should be like this (if your js code is in .blade.php
file)
$("#make").change(function(){
$.ajax({
url: "{{ route('chauffeur.ajax.vehicle') }}?make=" + $(this).val(),
method: 'GET',
success: function(data) {
$('#model').html(data.html);
}
});
});
try this.
Upvotes: 1