javascript - laravel 5 Ajax without a form -


im having problems sending ajax request using laravel 5.

this kicks of ajax request when clicked.

<td>     <i data-service="{{$performer['serviceid']}}" class="fa fa-eye"></i>{{$performer['name'] }} </td> 

ajax code

$(function() {     $('.fa-eye').click(function () {         var service = $(this).attr('data-service');          jquery.ajax({             crossdomain: true,             url: "/addwatchlist",             beforesend: function (xhr) {                 var token = $('meta[name="csrf_token"]').attr('content');                 console.log(token);                 if (token) {                     return xhr.setrequestheader('x-csrf-token', token);                 }             },             type: "post",             datatype: "json",             processdata: true,             data: {                 service: service             },             success: function( data ) {                alert(data);             },             error: function (error) {                 console.log(error);                 //alert("xhr=" + xhr + " b=" + b + " c=" + c);             }         });         alert('went past ajax');     }); }); 

now ajax request isn't reaching controller.

the error xhr=[object object] b=parsererror c=syntaxerror: unexpected token <

does know why happening?

maybe it's not answer question, if want pass token, add

"_token": "{{ csrf_token() }}" 

to data.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -