php-Ajax成功后刷新/重新加载页面-Laravel

在我的laravel项目中,我想在ajax成功之后刷新页面,但是在成功之后刷新页面.我试图用控制器中的laravel重定向刷新,但它不起作用,我也试图刷新ajax,什么都没发生?我该怎么做对?我该怎么做对?

控制者

if(request()->ajax()) {

            //do something             
            return ['success' => 'successfully done'];
            return redirect('admin/all')->with('status','Successfully done!');

JS

<script type="text/javascript">

        $('#master').on('click', function(e) {
         if($(this).is(':checked',true))  
         {
            $(".sub_chk").prop('checked', true);  
         } else {  
            $(".sub_chk").prop('checked',false);  
         }  
        });

        $('.approve_all').on('click', function(e) {

            var allVals = [];  
            $(".sub_chk:checked").each(function() {  
                allVals.push($(this).attr('data-id'));
            });  

            if(allVals.length <=0)  
            {  
                alert("Please select row.");  
            } 

            else {  



                var check = confirm("Are you sure you want to delete this row?");  
                if(check == true){  

                    var join_selected_values = allVals.join(","); 

                    $.ajax({
                        url: $(this).data('url'),
                        type: 'GET',
                        headers: {'X-CSRF-TOKEN': $('Meta[name="csrf-token"]').attr('content')},
                        data: 'ids='+join_selected_values,

                        success: function (data) {
                            if (data['success']) 
                            {

                                $("#" + data['tr']).slideUp("slow");
                                alert(data['success']);
                                location="/admin/all";


                            } 
                            else if (data['error']) 
                            {
                                alert(data['error']);
                            } 
                            else 
                            {
                                //alert('Whoops Something went wrong!!');
                            }
                        },
                        error: function (data) {
                            alert(data.responseText);
                        }
                    });
                                window.location.href="/your/url" ;

                  $.each(allVals, function( index, value ) 
                  {
                      $('table tr').filter("[data-row-id='" + value + "']").remove();
                  });
                }  

            }  


        $('[data-toggle=confirmation]').confirmation({
            rootSelector: '[data-toggle=confirmation]',
            onConfirm: function (event, element) {
                element.trigger('confirm');
            }
        });

        $(document).on('confirm', function (e) {
            var ele = e.target;
            e.preventDefault();

            $.ajax({
                url: ele.href,
                type: 'GET',
                headers: {'X-CSRF-TOKEN': $('Meta[name="csrf-token"]').attr('content')},
                success: function (data) {
                    if (data['success']) 
                    {

                        $("#" + data['tr']).slideUp("slow");
                        alert(data['success']);
                        location="/admin/all";

                    } 
                    else if (data['error']) {
                        alert(data['error']);
                    } 
                    else 
                    {
                        alert('Whoops Something went wrong!!');
                    }
                },
                error: function (data) {
                    alert(data.responseText);
                }
            });

            return false;
        });



    });

</script>

解决方法:

您需要使用javascript刷新页面.您可以使用location.reload()

 if ( data['success'] ) 
 {
     alert(data['success']);
     location.reload();
 } 

相关文章

IE6是一个非常老旧的网页浏览器,虽然现在很少人再使用它,但...
PHP中的count()函数是用来计算数组或容器中元素的个数。这个...
使用 AJAX(Asynchronous JavaScript and XML)技术可以在不...
Ajax(Asynchronous JavaScript and XML)是一种用于改进网页...
本文将介绍如何通过AJAX下载Excel文件流。通过AJAX,我们可以...
Ajax是一种用于客户端和服务器之间的异步通信技术。通过Ajax...