title: Refresh/Reload page after Ajax Sucess - Laravel
body: <p>In my laravel project, i want to refresh my page after an ajax success but my page would refresh after the success. I tried to refresh with laravel redirect in the controller and it didn't work, i have also tried to refresh in the ajax and nothing happened? How do i do this right? How do i do this right? </p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>if(request()-&gt;ajax()) {
  
              //do something             
              return ['success' =&gt; 'successfully done'];
              return redirect('admin/all')-&gt;with('status','Successfully done!');
  </code></pre>
  
  <p><strong>JS</strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
          $('#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 &lt;=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;
          });
  
  
  
      });
  
  &lt;/script&gt;
  </code></pre>