<form id="searchForm" action="searchProduct" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="text" id="wholeProdSearch" name="searchProd" placeholder="Search" class="wholeProdSearch">
<i class="search link icon"></i>
</form>
我有表单...我试图在用户点击进入时搜索某些内容。 这是js
$(document).ready(function() {
$('input.wholeProdSearch').on( 'keypress', function (e) {
if (e.which == 13) {
$('#searchForm').submit();
}
});
});
我有这条路线
Route::post('searchProduct','Retailer\ProductController@searchProduct');
仍然它在方法异常上抛出我的错误...与get方法一起工作得很好..但是当我尝试这个时..它仍然让我犯错误
错误是
**MethodNotAllowedHttpException in RouteCollection.php line 207:**
in RouteCollection.php line 207
at RouteCollection->methodNotAllowed(array('GET', 'HEAD')) in RouteCollection.php line 194
at RouteCollection->getRouteForMethods(object(Request), array('GET', 'HEAD')) in RouteCollection.php line 142
at RouteCollection->match(object(Request)) in Router.php line 729
at Router->findRoute(object(Request)) in Router.php line 652
at Router->dispatchToRoute(object(Request)) in Router.php line 628
at Router->dispatch(object(Request)) in Kernel.php line 214
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43
at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 115
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53
答案 0 :(得分:2)
尝试编写表单操作,如
{{ url('/searchProduct') }}
它会起作用
答案 1 :(得分:1)
问题是由于表单上的action="searchProduct"
属性无法正确解析为路径路径。
相反,您应该尝试使用route()
或url()
助手:
action="{{ url('/searchProduct') }}"
为了清晰起见,请为您的路线命名:
Route::post('searchProduct','Retailer\ProductController@searchProduct')->name('product.search');
然后使用route
帮助器:
action="{{ route('product.search') }}"