私はいくつかのデータトラフをajaxリクエストとして投稿しようとしています。Laravel 5.5 MethodNotAllowedHttpException ajax
これはhttp://mysite/element/edit/ {ID}
<script>
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$(function() {
$("#append-content").sortable({ handle: '.composer-row-header-handle' }).bind('sortupdate', function(e, ui) {
var rowID = $('.composer-row').map(function(){
return $(this).attr("id");
}).get();
$.ajax({
type: "POST",
url: "sort/store",
dataType: "json",
data: {
rowID: rowID
},
success: function(order){
console.log(rowID)
},
error: function(){
console.log(rowID)
}
});
});
});
</script>
を意味私のview.blade.php内のJavaScriptコードと同じファイル内に、私は相対_tokenメタ挿入した
<meta name="csrf-token" content="{{ csrf_token() }}">
そして私はルートファイル内にPOSTルートを設定しました
Route::post('element/edit/sort/store', '[email protected]');
そして、私のElementsConトローラのソート機能は
public function sort(Request $request)
{
$rowID = $request->input('rowID');
$i = 1;
foreach($rowID as $val) {
$val = str_replace("row-", "", $val);
DB::table('element')
->where('refID', 1)
->where('rowID', $val)
->update(
[
'rowORDER' => $i,
]
);
$i++;
}
}
である。しかし、その後、私は応答を記録順序を変更しようとすると、
jquery-1.12.0.min.js:4 POST http://mysite/element/edit/sort/store 500 (Internal Server Error)
と私は新しいページでリンクを開くしようとした場合、これは結果
ですすべての答え
を試してみてください'のため、' MethodNotAllowedHttpException'を取得しました。 ajaxコールについては、laravelログファイルを確認してください。 – aleksejjj
しかし、私はajaxをタイプ 'POST'を使うように指定しました –
あなたのajexがどんなルートに当っているのをチェックしましたか?それはあなたがコメントで言及したルートに当たっているのですか、他の何かを打っていますか? – Imran