I built and basic Jquery Ui slider:
$("#sliderNumCh").slider({
range: "min",
min: 0,
max: 20,
step: 1,
value: 20,
change : function(e, slider){
$('#sliderAppendNumCh').empty();
var getSliderVal = document.getElementById('sliderValue').value = sliderValue;
$('#sliderAppendNumCh').append(
<div class=\"form-group\" style=\"width:100%;margin:0 auto;\">
...
</div>);
},
slide : function(e , slider){
$('#number_of_chapters').val(slider.value);
},
});
My question is now how to post the slider value on each slide to my Laravel Controller.
I tried this:
$.ajax({
type: 'POST',
url: "{{Route('getAjaxRequest')}}",
headers: {'X-Requested-With': 'XMLHttpRequest'},
data: {value: getSliderVal},
success: function (option) {
console.log(getSliderVal);
}
});
route:
Route::post('create', ['as' => 'getAjaxRequest', 'uses' => 'ProductController@getAjaxRequest']);
and in my controller I tried to call and return the value like this:
public function getAjaxRequest()
{
$value = Request::get('value');
return view('productRom.edit')->with('value', $value);
}
so basically I want to get the slider value and later on return the value to a php function, to use that value for example in a loop.
I am not used to Ajax and therefor not sure what I am doing wrong.
Edit I tried Jose Rojas suggestion:
public function getAjaxRequest()
{
$value = Request::get('value');
//do your stuff
return $slideValue;
}
And I get following error in the console:
http://localhost/myapp/public/product/edit/%7BproductID%7D 500 (Internal Server Error)
the actual url is:
Edit
this is my route:
Route::get('edit/{productID}', ['as' => 'editProduct', 'uses' => 'ProductController@editProduct']);