I want to send data to the controller with ajax, but there is an error
Missing required parameters for `[Route: city] [URI: daftar / city / {id}].
here’s my ajax code
$(".province").on("change",function(){
var id = this.value;
console.log(id);
$.ajax({
type: "get",
url: "{{ route('city') }}"+'/'+id ,
dataType: "json",
success: function(data){
console.log('');
},
});
});
and this my route
Route::group(['prefix' => 'vendor'], function () {
Route::get('/city/{id}', 'VendorVendorController@getCity')->name('city');
});
4
Answers
You are using
without any parameter, so you need to change your route with this code:
Try This.
AjAX.
you can’t write it this way.
{{ route('city') }}
is echoing the route which has a parameter. but the parameter is missing here. you are adding that parameter later using js but it won’t work as its missing when php is echoing the route. you can do it this wayYou can’t use route(‘city’) without its parameter,
If you want a simple way without the laravel helper you can try to change it like this :