vendredi 7 septembre 2018

laravel ajax login response error JSON.parse: unexpected non-whitespace

hello everyone i got a problem with my laravel ajax login, he is still having the error: SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 2 of the JSON data

this is my ajax code:

$('#loginForm').submit(function(e) {
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        e.preventDefault();
        var formul=$('#loginForm');
        var formurl = $(formul).attr('action');
        var form = $('#loginForm').serialize();
        $(this).loading();
        //var form={document:$('#document').val(),password:$('#password').val(),}
        $.ajax({
            url: formurl,
            type: "POST",
            data:form,
            // data: new FormData(form[0]),
            // cache: false,
            // datatype: 'JSON',
            // processData: false,
            // contentType: false,
            success: function (data) {
                if (data.auth) {
                    $('#loginForm').hide();
                    window.location.href = APP_URL + '/cuenta';
                }
                // window.location.href = SITE_URL+data.intended;
                else
                    $('#loginForm #errorMsg').show().text(data.error);
                $(formul).loading('stop');
            },
            error: function (jqXHR, textStatus, errorThrown) {
                    errorAjax(jqXHR, textStatus, errorThrown);
                }
        });
}

and there is my php code

    protected function authenticated(Request $request, $user)
{
    if ($request->ajax()) {
        if (Auth::attempt(['document' => $request->document,'document_type' => $request->document_type, 'password' => $request->password, 'status' => 1])) {
            // The user is active, not suspended, and exists.
            Auth::login($user);
        return response()->json([
            'auth' => auth()->check(),
            'user' => $user,
            'intended' => $this->redirectPath(),
        ]);
        }
        else{
        Auth::logout();
        return redirect()->back()
            ->withErrors('Usuario inactivo');
        }
    }
}

and this is the response responseText: "000000000000000000000000{\"auth\":true,\"user\":12,\"intended\":\"\/home\"}"

can someone please help me, i got a lot of time trying to solve this.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2M7V2xp
via IFTTT

Aucun commentaire:

Enregistrer un commentaire