title: window.location.replace not working Laravel ajax
body: <p>i am a beginner of laravel. i made the custom login form using laravel Ajax.when enter the username and password and click sign in button it is successfully visit to test.blade.php page but page displayed 404
  Not Found what tried so far i attached below.</p>
  <p><strong>test.blade.php</strong></p>
  <pre><code>&lt;div class=&quot;container&quot;&gt;
      &lt;table width=&quot;100%&quot; height=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; align=&quot;center&quot;&gt;
          &lt;tr&gt;
              &lt;td align=&quot;center&quot; valign=&quot;middle&quot;&gt;
                  &lt;table class=&quot;table-bordered&quot; width=&quot;350&quot; border=&quot;0&quot; cellpadding=&quot;3&quot; cellspacing=&quot;3&quot; bgcolor=&quot;#FFFFFF&quot;&gt;
                      &lt;form name=&quot;frm_login&quot; id=&quot;frm_login&quot;&gt;
                      @csrf
                            &lt;tr&gt;
                                &lt;td height=&quot;25&quot; colspan=&quot;2&quot; align=&quot;left&quot; valign=&quot;middle&quot; bgcolor=&quot;#FF9900&quot; class=&quot;style2&quot;&gt;
                                    &lt;div align=&quot;center&quot;&gt;
                                        &lt;strong&gt;Login&lt;/strong&gt;
                                    &lt;/div&gt;
  
                                &lt;/td&gt;
                            &lt;/tr&gt;
  
                          &lt;tr&gt;
  
                              &lt;div id=&quot;err&quot; style=&quot;color: red&quot;&gt;
  
  
                              &lt;/div&gt;
  
                          &lt;/tr&gt;
  
  
                          &lt;tr&gt;
                              &lt;td width=&quot;118&quot; align=&quot;left&quot; valign=&quot;middle&quot; class=&quot;style1&quot;&gt;Username&lt;/td&gt;
                              &lt;td width=&quot;118&quot; align=&quot;left&quot; valign=&quot;middle&quot; class=&quot;style1&quot;&gt;
                                  &lt;input type=&quot;text&quot; class=&quot;form-control&quot; size=&quot;10px&quot; id=&quot;username&quot; placeholder=&quot;Username&quot; name=&quot;username&quot;&gt;
                              &lt;/td&gt;
  
                          &lt;/tr&gt;
  
                          &lt;tr&gt;
                              &lt;td width=&quot;118&quot; align=&quot;left&quot; valign=&quot;middle&quot; class=&quot;style1&quot;&gt;Password&lt;/td&gt;
                              &lt;td width=&quot;118&quot; align=&quot;left&quot; valign=&quot;middle&quot; class=&quot;style1&quot;&gt;
                                  &lt;input type=&quot;password&quot; class=&quot;form-control&quot; size=&quot;10px&quot; id=&quot;password&quot; placeholder=&quot;password&quot; name=&quot;password&quot;&gt;
                              &lt;/td&gt;
  
                          &lt;/tr&gt;
  
                         
  
                          &lt;tr&gt;
                              &lt;td colspan=&quot;2&quot; align=&quot;right&quot; valign=&quot;middle&quot; class=&quot;style1&quot;&gt;
  
                                  &lt;button type=&quot;button&quot; class=&quot;btn btn-primary&quot; onclick=&quot;login()&quot;&gt;Sign In&lt;/button&gt;
                                  &lt;button type=&quot;button&quot; class=&quot;btn btn-warning&quot; onclick=&quot;reset()&quot;&gt;Reset&lt;/button&gt;
                                  &lt;/td&gt;
  
  
                          &lt;/tr&gt;
  
  
  
  
  
  
                      &lt;/form&gt;
                  &lt;/table&gt;
  
              &lt;/td&gt;
  
  
          &lt;/tr&gt;
  
  
      &lt;/table&gt;
  
  
  
  
  
  &lt;/div&gt;
  
  
  &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js&quot;&gt;&lt;/script&gt;
  
  
  
  
  &lt;script&gt;
  
      function login()
      {
          if($('#username').val() == &quot;&quot;)
          {
              $('#username').parent('td').addClass('has-error');
              return false;
          }
          else if($('#password').val() == &quot;&quot;)
          {
              $('#password').parent('td').addClass('has-error');
              return false;
          }
          else if($('#utype').val() == &quot;&quot;)
          {
              $('#utype').parent('td').addClass('has-error');
              return false;
          }
          var data = $(&quot;#frm_login&quot;).serialize();
  
          $.ajaxSetup({
              headers: {
                  'X-CSRF-TOKEN': $('meta[name=&quot;csrf-token&quot;]').attr('content')
              }
          });
  
  
  
  
          $.ajax({
                  type : 'POST',
                  url: '{{ route('testlogin.check') }}',
                  data : data,
  
              success : function(response)
              {
                  console.log(response);
                  if(response == 1)
                  {
                      window.location.replace('test.blade.php');
                  }
                  else if(response == 3)
                  {
                      $(&quot;#err&quot;).hide().html(&quot;Username or Password or Role Incorrect. Please Check&quot;).fadeIn('slow');
                  }
              }
  
          });
      }
  
  &lt;/script&gt;
  </code></pre>
  <p><strong>testContoller</strong></p>
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  
  class TestloginController extends Controller
  {
      public function index()
      {
          return view('testlogin');
      }
  
      public function check(Request $request)
  {  
      $user = $request-&gt;username;
      $pass  = $request-&gt;password;
  
      if (auth()-&gt;attempt(array('name' =&gt; $user, 'password' =&gt; $pass)))
      {
          return response()-&gt;json([ [1] ]);
      } 
      else
       {  
          return response()-&gt;json([ [3] ]);
       }  
  }
  
      public function logout(Request $request) 
      {
          Auth::logout();
          $request-&gt;session()-&gt;flush();
          return redirect()-&gt;route('student.login');
      }
  }
  </code></pre>
  <p><strong>Routes</strong></p>
  <pre><code>Route::get('/test','TestloginController@index');
  Route::post('/test/check','TestloginController@check')-&gt;name('testlogin.check');
  </code></pre>
  <p>Route::get('/test','TestloginController@index')-&gt;name('testlogin.login');</p>