I built an ajax post which sends each slider value (I am using jquery ui slider) to my controller.
The Ajax code:
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: 'post',
contentType: "application/json",
url: "{{ Route('editProductPost', $product->id) }}",
headers: {
'X-Requested-With': 'XMLHttpRequest'
},
data: JSON.stringify({
value: getSliderVal,
productId : getPrId
}),
datatype: 'json',
success: function(response) {
// get response
console.log(response.sliderValue)
}
});
And in my Controller I am doing this:
public function editProductPost(Request $request)
{
Log::info($request->get('value'));
return view('product.edit', [
'sliderValue' => $request->get('value')
]);
}
This returns me the correct slider value,
Log::info($request->get('value'));
But I get this error message in my browser console:
POST http://localhost/myApp/public/product/edit/98 500 (Internal Server Error)
Later on I want to call this sliderValue inside of a php loop in my view.
Edit
I do have a csrf token:
<meta name="csrf-token" content="{{ csrf_token() }}">
Edit
I have done this:
$sliderValue = $request->get('value');
$route = 'updateProduct';
return view('product.edit', compact(['sliderValue', 'route']))->render();
The console print me undefined and if I do this {{ sliderValue }} I get an error that sliderValue is not defined
error:function(response){ console.log(response.responseText); }- jaysingkar