这是我的带有动作xhr的AMp表格
<form method="post" action-xhr="{{ url('/ampsearch') }}" target="_top">
<input class="search-toolbar__field js-search-field" type="text" placeholder="Srarch" value="beet" name="var" autocomplete="off">
<input class="search-toolbar__cta" type="submit">
</form>
Routes
Route::post('/ampsearch', 'User\HomeController@ampsearch')->name('ampsearch');
Route::get('/searchresult', 'User\HomeController@searchresult')->name('searchresult');
在这里,我在action-xhr中提到了rout uri(用于调用控制器)。
这是我的控制器代码:
public function ampsearch(Request $request)
{
$post = $request->all();
$var = $post['var'];
Session::put('var', $var);
if($var==null || $var=='' || $var==' ')
{
$res_product = array();
$response['key_word'] = $var;
return view('ampsearch')->with('data', $response);
}
else
{
$res_product = Product::where('prod_name', 'LIKE', '%'.$var.'%')
->orWhere('prod_description', 'LIKE', '%'.$var.'%')->get();
$response['data'] = $res_product;
$response['key_word'] = $var;
return view('ampsearch')->with('data', $response);
}
}
所以我收到此错误:
Symfony \组件\ HttpKernel \异常\ MethodNotAllowedHttpException enter image description here