Laravel 护照使用 api 且 js 不工作
Laravel passport consuming api with js not working
我正在尝试按照 laravel 文档 here 中指示的方式使用 ajax (axios) 请求来使用我的 api。但它不起作用,显示如下图所示的错误
我的示例 header 响应如下所示:
我的 ajax 请求如下所示:
axios.get('http://localhost:81/test_laravel/public/api/user')
.then(function(response){
console.log('Component mounted.')
})
.catch(function(error){
console.log(error.response.status)
});
不知道发生了什么。请帮忙。
如果我像这样在 \App\Http\EncryptCookies.php 文件中进行更改,这将起作用:
<?php
namespace App\Http\Middleware;
use Illuminate\Contracts\Encryption\Encrypter as EncrypterContract;
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
class EncryptCookies extends Middleware
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array
*/
protected static $serialize = true;
protected $except = [
//
];
public function __construct(EncrypterContract $encrypter)
{
parent::__construct($encrypter);
}
}
通过添加行 protected static $serialize = true;
来更改 $serializable 的值。
我正在尝试按照 laravel 文档 here 中指示的方式使用 ajax (axios) 请求来使用我的 api。但它不起作用,显示如下图所示的错误
我的示例 header 响应如下所示:
我的 ajax 请求如下所示:
axios.get('http://localhost:81/test_laravel/public/api/user')
.then(function(response){
console.log('Component mounted.')
})
.catch(function(error){
console.log(error.response.status)
});
不知道发生了什么。请帮忙。
如果我像这样在 \App\Http\EncryptCookies.php 文件中进行更改,这将起作用:
<?php
namespace App\Http\Middleware;
use Illuminate\Contracts\Encryption\Encrypter as EncrypterContract;
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
class EncryptCookies extends Middleware
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array
*/
protected static $serialize = true;
protected $except = [
//
];
public function __construct(EncrypterContract $encrypter)
{
parent::__construct($encrypter);
}
}
通过添加行 protected static $serialize = true;
来更改 $serializable 的值。