jquery - Ajax POST Request in Larvael -


i'm sending value named text <script> tag in .blade.php file controller using post ajax request. if not write $.post function gives me output of text value in console. when write ajax request send data controller value not pass. in short, want pass value view controller , unable that. have tried youtube tutorials , previous stack overflow questions. visited laracasts problem not solved. doing wrong? please help. thank you.

shopreq.blade.php:

{{csrf_field()}} <script>     $(document).ready(function(){         $('.ouritem').click(function(event){                 var text=$(this).text();                 $('#additem').val(text);                  console.log(text);                 $.post('shopreq',{'text':text,'_token':$('input[name=_token]').val()}),function(data){                     console.log(data);                 });         });     }); </script> 

web.php:

route::post('shopreq','usercontroller@special'); 

controller:

class usercontroller extends controller {        public function special(request $request){         $articles = db::table('shoppingtrips')->get();         echo"done";   //      return $request->all();     } } 

try below ajax syntax:

$.ajax({     url: 'your route',     method: 'post',     data: {         key1: value1         // can send more such key value pair here     },      headers: {         'x-csrf-token': $('meta[name="csrf-token"]').attr('content')     },     success: function(response){      } }); 

don't forget add csrf-token, otherwise 500 (internal server error) required post request.


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