我的ajax(在vue组件中)像这样:
<template>
...
<a class="text-right" @click="detail">
Detail
</a>
...
</template>
<script>
export default{
...
methods:{
...
detail() {
this.$http.post(window.BaseUrl + '/shop/',{data: JSON.stringify(this.data)}).then(function (response) {
...
}).catch(function(error){
...
});
}
}
}
</script>
如果用户点击链接,则会调用详细信息方法
详细用于通过ajax发送数据的方法
它会在laravel中路由
这样的路线:
Route::group(['prefix' => 'shop','as'=>'shop.'], function () {
Route::post('/', 'ShopController@index');
...
});
然后该路线将致电店控制器
控制器是这样的:
public function index(Request $request)
{
$param = $request->only('data');
$list = $this->shop_service->getList($param['cart_cache']);
return view('shop.index',compact('list'));
}
如果代码已执行,我希望它会重定向到查看刀片laravel(return view('shop.index',compact('list'));
)
我该怎么做?
答案 0 :(得分:1)
您可以重定向到Ajax成功路由,这将在控制器中调用您想要的功能,如下所示:
<强>的Ajax 强>
success:function(){
window.location.href(base_url+"/get/data");
});
为此,您应该具有以下路线和控制器功能
<强>路线强>
Route::get('/get/data','YourController@getData');
<强>控制器强>
public function getData(){
$list = // here write code to get desired data.
return view('shop.index',compact('list'));
}
希望你明白。