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


we can use ajax post request transfer value view controller. i'm doing , passing value view controller. can use ajax post request transfer value 1 view view? doing laravel suggests. unsuccessful in this. doing wrong? please help. thank you. here 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;         // stuff $text         $projects=db::table('projects')->where('projects.type', '=', $text)->get();         return view('show',compact('projects'));     } 

you can see i'm using compact function transferring value view named show.blade.php, not transferring value. how can transfer show.blade.php? know using get method 1 can transfer value. want transfer using post request.

how ajax works

how ajax works

as can see on right side box 2nd bullet point. when make ajax request, has response returns original caller.

your web.php , controller seems fine. when make ajax request, hits special function when return view('show',compact('projects')); return view html response ajax call (you can see html in console log). means can not load new view ajax.

you can use regular synchronous calls load new. :)

or if want update content on same page can refer below link

how can return view ajax call in laravel 5


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -