I’m trying to return a view with some data in it with ajax
I tried like this:
$.ajax({
url: '/canvas',
data:{
size:data.drawing['canvas_size'],
name: data.drawing['name'],
id: data.drawing['id']
}
});`
and this is the route:
Route::get('canvas/{size}/{name?}/{id?}',[DrawingController::class,'canvas'])->name('canvas');
it just gives the 404 error,can you help me please?
2
Answers
Either send the data in the uri using the route
like this
Or send the data in the body / url query string using the route
using
and get the variable inside your controller with
DrawingController
Note: This answer will only work in a
blade.php
file.Route parameters are used for readable urls. Do this your request with request GET parameters. So update your route:
And use:
You can also follow a directive like this if you want to use it with route parameters. But putting variables from javascript here can mess things up: