dimanche 20 août 2017

Passing value from one view to another view by AJAX Post Request in Laravel

we can use AJAX Post request to transfer value from view to Controller. I'm doing this and successfully passing value from view to Controller. But can I use AJAX Post request to transfer value from one view to another view? I am doing this as Laravel suggests. But unsuccessful in this. Am I doing something wrong? Please help. Thank you. Here is my code:

Page.blade.php:

`<script>
    $(document).ready(function(){
            $('a#one').on('click', function () {
            var text=$(this).text();
            console.log(text);
            $.ajax({
                url: APP_URL+'/show',
                method: 'post',
                data: {
                    text: text
                },
                success: function(response){
                    console.log(response);
                }
            });
        });
    });
</script>`

web.php:

`Route::post('show','UserController@special');
Route::get('/show' , [
    'uses' => 'UserController@special1',
    'as' => 'show'
]);`

Controller:

`public function special(Request $request){
        $text = $request->input('text'); 
        echo " dsds ".$text;
        // do stuff with $text
        $projects=DB::table('projects')->where('projects.type', '=', $text)->get();
        return view('show',compact('projects'));
    }`

You can see that I'm using compact function for transferring value to another view named show.blade.php, but it is not transferring value. How can I transfer it to show.blade.php? I know that using GET method one can easily transfer value. But I want to transfer it by using POST request.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2xgGyUN
via IFTTT

Aucun commentaire:

Enregistrer un commentaire