title: Ajax Request in laravel 4
body: <p>I'm newbie in laravel. I'm using version 4 and i'm trying to do ajax request in my login form. Since my login form is in bootstrap modal, before the form submit it will check if the input password and username are equal to password and username in my database using ajax. Then if the form submit it will reload only the page.
  here is my code:</p>
  
  <p><strong>js-script.php</strong></p>
  
  <pre><code> $("#login-submit").submit(function(event) {
    var un = 'input[name="username"]';
    var pw = 'input[name="password-login"]';
  
     $.ajax({ 
                  type: "POST", 
                  url: "/login=success",
                  data : { 'un' : $(un).val(), 'pw' : $(pw).val() },  
                  datatype: "json", 
                  success: function(data){  
                      if(data == 0){
                          $('#message-error').show();
                          setTimeout(function() {
                               $('#message-error').hide();
                          }, 5000);
                      }
                      if(data != 0){
                          window.location.reload();
                      }
                  }
              });
  
  });
  </code></pre>
  
  <p><strong>usercontroller.php</strong></p>
  
  <pre><code>// Login User
      public function login(){
          $un = Input::get( 'un' );
          $pw = Input::get( 'pw' );   
          $password = md5($pw);
          if (Auth::attempt(array('username'=&gt;$un, 'password'=&gt;$password))) {
              return Redirect::to('/login=success')-&gt;with('message', 'You are now logged in!');
          } else {
              return Redirect::to('users/login')
                  -&gt;with('message', 'Your username/password combination was incorrect')
                  -&gt;withInput();
          }     
  
      }
  </code></pre>
  
  <p><strong>route.php</strong></p>
  
  <pre><code>Route::post('/login=success', 'UserController@login');
  </code></pre>
  
  <p>i dont know how to access my database and do some queries in my ajax.</p>