我使用了来自laravel/spatie package的laravel pjax插件
当我点击登录和注册链接(基本laravel auth)时,它会被罚款。 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)
...
我的代码中缺少什么? 我不知道如何解决这个错误。谁能解释为什么会出现这种错误?
<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>
这是使用pjax提交表单的正确方法(不重新加载页面)吗?
这是我的应用布局
<!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>
答案 0 :(得分:0)
当我删除pjax插件并尝试正常登录时,我发现它显示错误
SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)
所以我意识到我忘了在.env文件中配置DB_USERNAME和DB_PASSWORD。
我输入正确的USERNAME和PASSWORD并安装回pjax插件。它完美地运作。 :)
我认为如果请求中有错误,FilterIfPjax类会抛出错误422.我不确定:)