Laravel Passport return 401 with Select2 ajax

774 views Asked by At

I am using the Select2 plugin v 3.5.1 and I am trying to load remotely with ajax the options, but I get 401 from Laravel Passport.

When I make other requests with jQuery ajax the result is the same, but when I use VueJS the request succeeds.

Any ideas, why this is happening?

1

There are 1 answers

0
yanko-belov On

The problem was that I didn't set the csrf token .. This code fixed the issue:

$.ajaxSetup({
   headers: {
     'X-CSRF-Token': window.Spark.csrfToken
   }
});