laravel 和甜蜜的警报并重定向到

laravel and sweetalert and rederect to

我使用 laravel 5.8,如果我插入或更新页面时遇到问题,而不是返回到页面列表。

后控制器: 我使用:return response()->json('Post Created'); 我使用 ajax 文件和此代码:

$.ajax({
            type: 'POST',
            url: this.action,
            data: new FormData(this),
            dataType: 'json',
            contentType: false,
            cache: false,
            processData:false,

            success: function(response){ 
                
                Sweet('success',response)
                
                success(response)

            },
            error: function(xhr, status, error) 
            {
                $('.errorarea').show();
                $.each(xhr.responseJSON.errors, function (key, item) 
                {
                    Sweet('error',item)
                    $("#errors").html("<li class='text-danger'>"+item+"</li>")
                });
                errosresponse(xhr, status, error);
            }
        })


    });

如果它被插入或更新但它没有返回到我的列表,我会收到一条很好的消息,希望你明白我的意思。

如果您想在成功后重定向,请执行以下操作:

$.ajax({
        type: 'POST',
        url: this.action,
        data: new FormData(this),
        dataType: 'json',
        contentType: false,
        cache: false,
        processData:false,

        success: function(response){ 
            
            Sweet('success',response)
            
            success(response)
            window.location.href = "url you want to redirect to";

        },
        error: function(xhr, status, error) 
        {
            $('.errorarea').show();
            $.each(xhr.responseJSON.errors, function (key, item) 
            {
                Sweet('error',item)
                $("#errors").html("<li class='text-danger'>"+item+"</li>")
            });
            errosresponse(xhr, status, error);
        }
    })


});