doulan8330 2018-05-29 07:35
浏览 30

AJAX登录表单需要允许浏览器cookie

I have a laravel project and I wrote a login form with AJAX.

But it returns an error if user's browser doesn't allow cookies.

And many users with safari browser can not login. How can I fix this?

Sample Html:

<form id="loginForm" class="validate-form" role="form" method="POST" 
            action="{{ url('/login') }}">
       {{ csrf_field() }}

   Email :
   <input type="text name="email">

   password:
   <input type="password" name="password">

</form>

My JS code:

$modal.find('form').submit(function () {
    $('.login100-form-btn').attr('disabled', true);
    $.ajax({
        type: 'POST',
        url: $(this).attr('action'),
        data: $(this).serialize(),
        dataType: 'json',
        cache: false,
        success: function (data) {...},
        error: function (xhr, ajaxOptions, thrownError) {...}
       });
    return false;
});

Part of Laravel LoginController:

protected function attemptLogin(Request $request)
{
     $credentials = $this->credentials($request);
     return $this->guard()->attempt(
        $credentials, $request->has('remember')
    );
 }

protected function sendLoginResponse(Request $request)
{
    $request->session()->regenerate();

    $this->clearLoginAttempts($request);

    if ($request->expectsJson()) {
        return response()->json([
            'ok'       => true,
            'success'  => true,
            'intended' => URL::previous(),
        ], 200);
    }

    return $this->authenticated($request, $this->guard()->user())
        ?: redirect()->intended($this->redirectPath());

}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程