I need to pass only one value from view to controller,using Ajax(in View home.blade.php). All solutions are for Laravel 5's and it's not helpful.
Ajax from home.blade.php:
$datee="hello";
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type : 'POST',
url : "insert2",
contentType: "text",
data: datee ,
dataType: 'json'
});
Route:
Route::post('/insert2/{datee}', 'EditContdroller@show1');
Route::get('/home', 'HomeController@index')->name('home');
And EditController's method:
public function show1(Request $request){
$data= $request->datee;
//some work with $data...
return $json_Value;
}
I get Error 404 Post .../insert2 not found.Have you any idea,please?
{datee}parameter from your laravel route. Also add a slash before the url in your ajax callurl: "/insert2",and send the data as objectdata: {datee: datee},.X-Requested-Withheader to ajaxSetup$.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') , 'X-Requested-With': 'XMLHttpRequest', } });.Add the csrf token to the data toodata: {datee: datee, _token: $('meta[name="csrf-token"]').attr('content') }