Laravel护照消费API与JS不起作用

Laravel护照消费API与JS不起作用

本文介绍了Laravel护照消费API与JS不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ajax(axios)请求来使用我的api,这是laravel文档此处.但它不起作用,并显示如下图所示的错误

I am trying to consume my api using ajax (axios) request as the way it is instructed in laravel docs here. But it is not working, shows errors like the following image

我的示例标头响应如下所示:

My sample header response looks likes the following:

我的ajax请求看起来像这样:

My ajax request looks like this:

   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)
            });

不知道发生了什么.请帮忙.

Don't have a clue what is going on. Please help.

推荐答案

如果我在\ App \ Http \ EncryptCookies.php文件中进行如下更改,则此方法有效:

This works if I make a change in the \App\Http\EncryptCookies.php file like this:

<?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的值.

Changing the value of $serializable by adding the line protected static $serialize = true; works.

这篇关于Laravel护照消费API与JS不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 07:05