私はlaravelにフォームを持っています。なぜメソッドはHTTP例外を許可されていませんか?
私は、ajax投稿要求を使用してサーバーにデータを送信したいと考えています。
エラーが発生します。どうしてか分かりません?
My view source url is : http://localhost/lily/public/search
(1/1)MethodNotAllowedHttpException
RouteCollection.phpで(ライン251)
RouteCollection-で> methodNotAllowed(配列( 'GET'、 'HEAD')) RouteCollection.phpで
(ライン238)
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
$("#submit").submit(function(){
var name = $("#name").val();
console.log(name);
$.ajax({
type: "POST",
url : "{{url('/search')}}",
data : name ,
success : function(data)
{
console.log(data)
},
error : function(error)
{
console.log(error)
}
});
});
});
</script>
<div class="col-md-6 offset-3">
<form id="submit" method="POST">
<input type="name" name="name" id="name">
<button type="submit" class="btn btn-success">search</button>
</form>
</div>
</body>
</html>
Route::post('/search/{name}', '[email protected]');
public function in() {
return json("fdfdfdfdfdf");
}
使用しているメソッドのルートが存在しますか。 POST、PUT、DELETEなど?また、CSRF保護を有効にしていますか?あなたはトークンを通過する必要があります。 https://laravel.com/docs/5.5/csrf#csrf-x-csrf-token – Mike
生成されたフォームアクションの実際の内容は何ですか? – Amarnasan
これはTokenMismatchException – Bugfixer