各スライダ値(私はjquery UIスライダを使用しています)をコントローラに送信するajaxポストを作成しました。Laravel Ajax Post returns 500
Ajaxコード:
public function editProductPost(Request $request)
{
Log::info($request->get('value'));
return view('product.edit', [
'sliderValue' => $request->get('value')
]);
}
これは私に正しいスライダー値を返し、
Log::info($request->get('value'));
しかし、私はこれを取得:
$.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)
}
});
そして
は私のコントローラで私はこれをやっていますブラウザのコンソールにエラーメッセージ:POST http://localhost/myApp/public/product/edit/98 500 (Internal Server Error)
後で私の意見では、このsliderValue
をPHPループの内側にしたいと思います。私はCSRFトークンを持っている
編集
:
<meta name="csrf-token" content="{{ csrf_token() }}">
編集
私はこの行っている:コンソールは私を印刷
$sliderValue = $request->get('value');
$route = 'updateProduct';
return view('product.edit', compact(['sliderValue', 'route']))->render();
を私はこれ{{ sliderValue }}
を行う場合、私はsliderValue
はあなたのコードの
Log :: info($ request-> get( 'value'));を取得した場合は、値の場合、ビューの代わりにjsonデータを返す必要があります。 – hizbul25
@ hizbul25私は以前これを行っていましたが、私のようなビューで変数を使用することはできません(PHPループ内で) – utdev
'error:function(response){ console.log(response.responseText); } ' – jaysingkar