moses toh
moses toh

Reputation: 13182

How can I make it return to view blade laravel after ajax process?

My ajax (in vue component) like this :

<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>

If user click a link, it will call detail method

In detail method used to send data via ajax

It will routes in laravel

The route like this :

Route::group(['prefix' => 'shop','as'=>'shop.'], function () {
    Route::post('/', 'ShopController@index');
    ...
});

Then the route will call shop controller

The controller like this :

public function index(Request $request)
{
    $param = $request->only('data');
    $list = $this->shop_service->getList($param['cart_cache']);
    return view('shop.index',compact('list'));
}

If the code executed, I want it will redirect to view blade laravel (return view('shop.index',compact('list'));)

How can I do it?

Upvotes: 0

Views: 2394

Answers (1)

Sagar Gautam
Sagar Gautam

Reputation: 9389

You can redirect to route in Ajax success which will call your desired funtion in controller like this:

Ajax

success:function(){
    window.location.href(base_url+"/get/data");
});

For this to work, you should have following route and controller function

Route

Route::get('/get/data','YourController@getData');

Controller

public function getData(){      

    $list = // here write code to get desired data.

    return view('shop.index',compact('list'));
}

Hope you understand.

Upvotes: 1

Related Questions