简体   繁体   English

Laravel 5.4-pjax响应错误的不可处理实体

[英]Laravel 5.4 - pjax response an error Unprocessable Entity

I used laravel pjax plugins from laravel/spatie package 我使用了laravel / spatie包中的 laravel pjax插件

When i clicked the Login and Register link (basic laravel auth), it works fined. 当我单击“登录和注册”链接(基本laravel身份验证)时,它可以正常运行。 Pjax is working, but when i tried to login it shows an error . Pjax在工作,但是当我尝试登录时显示错误。

(1/1) HttpException
in Application.php (line 926)
at Application->abort(422, '', array())
in helpers.php (line 30)
at abort(422)
in FilterIfPjax.php (line 87)
at FilterIfPjax->fetchContainer(object(Crawler), '#body')
in FilterIfPjax.php (line 54)
at FilterIfPjax->filterResponse(object(Response), '#body')
in FilterIfPjax.php (line 35)
at FilterIfPjax->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
...

Something missing in my code ? 我的代码中缺少什么? I have no idea how to fix this error. 我不知道如何解决此错误。 anyone can explain why this error occurs ? 任何人都可以解释为什么会发生此错误?

<script type="text/javascript">
        $(document).ready(function(){
            if ($.support.pjax) {
                $.pjax.defaults.timeout = 2000; // time in milliseconds
                $(document).pjax('a', '#body');
                $(document).on('submit', 'form[data-pjax]', function(event) {
                    $.pjax.submit(event, '#body');
                });
            }
        });
    </script>

Is this the correct way in submitting the forms in using pjax (without reloading the page) ? 这是使用pjax提交表单的正确方法(无需重新加载页面)吗?

Here is my app layout 这是我的应用布局

<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ config('app.name', 'Laravel') }}</title>

    <!-- Styles -->
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}"></script>
    <script type="text/javascript" src="{{asset('js/jquery.pjax.js')}}"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            if ($.support.pjax) {
                $.pjax.defaults.timeout = 2000; // time in milliseconds
                $(document).pjax('a', '#body');
                $(document).on('submit', 'form[data-pjax]', function(event) {
                    $.pjax.submit(event, '#body');
                });
            }
        });
    </script>
</head>
<body id="body">
    ....
   @yield('content')
</body>
</html>

I figured out when I remove the pjax plugins and tried to login nomally it shows an error 我发现当我删除pjax插件并尝试以名义上登录时它显示了一个错误

SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)

So i realized that i forgot to configure the DB_USERNAME and DB_PASSWORD in .env file . 所以我意识到我忘了在.env文件中配置DB_USERNAME和DB_PASSWORD。

I put the correct USERNAME and PASSWORD and install back the pjax plugin. 我输入了正确的USERNAME和PASSWORD,然后重新安装了pjax插件。 It works perfectly. 它运作完美。 :) :)

I think FilterIfPjax Class throws the error 422 if there's an error in request.. i'm not sure of that :) 我认为,如果请求中有错误,FilterIfPjax类会引发错误422。我不确定:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM