Tartalomjegyzék

< Laravel API

Laravel API - JavaScript kliens

JavaScript

fetch()

const token = '3|7eBr5iAUPgqQz3lxIFgC72Yh3ERO76g1MyuHNOGD';
const url = 'http://localhost:8080/api/employees/search/László';
 
fetch(url, {
  headers: {
    Authorization: `token ${token}`
  }
})
  .then(res => res.json())
  .then(json => console.log(json));

jQuery $.ajax()

const url = 'http://localhost:8000/api/employees';
const token = '3|7eBr5iAUPgqQz3lxIFgC72Yh3ERO76g1MyuHNOGD';
 
$.ajax({
   url: url,
   type: 'get',
   contentType: 'application/json',
   headers: {
      'Authorization': `Bearer ${token}`
   },
   success: function (result) {
       console.log(result);
   },
   error: function (error) {
       console.log(error);
   }
});