title: Boostrap login popup model validation using jquery ajax and codeigniter
body: <p>MY Question: i click login button and open login popup model and i insert username and password and press submit button ,when if username and password is correct then redirect dashboard page ,and if username and password wrong then display error message in popup model. i used codeigniter fremework.please help me...</p>
  
  <p><strong>controller:</strong></p>
  
  <pre><code>class Property extends CI_Controller {
  
      public function __construct() {
          parent::__construct();
          $this-&gt;load-&gt;library('session');
      }
  
      public function index() {
          $username = $this-&gt;input-&gt;post('username');
          $password = $this-&gt;input-&gt;post('password');
          if ($username == 'admin' &amp;&amp; $password == 'admin') {
              $user = array(
                  'username' =&gt; $username,
                  'password' =&gt; $password
              );
              $this-&gt;session-&gt;set_userdata($user);
              echo json_encode($user);
          } else {
              $errormsg = "Invalid UserName and Password";
              echo json_encode($errormsg);
          }
      }
  
      public function property_owner_detail() {
          $username = $this-&gt;session-&gt;userdata('username');
          if (!empty($username)) {
              //$this-&gt;output-&gt;cache(3600);
              $this-&gt;load-&gt;model('event_model');
              $this-&gt;load-&gt;helper('date');
              $data = array(
                  'page_title' =&gt; 'Property',
                  'location_collection' =&gt; $this-&gt;event_model-&gt;list_all()
              );
              $this-&gt;load-&gt;view('property/index', $data);
          } else {
              redirect('/Site');
          }
      }
  
  }
  </code></pre>
  
  <p><strong>View:</strong></p>
  
  <pre><code>&lt;li&gt;&lt;a href="#" style="color: red" data-toggle="modal" data-target="#property_owner_login"&gt;Login&lt;/a&gt;&lt;/li&gt;
  
  
  &lt;div class="modal fade" id="property_owner_login" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"&gt;
      &lt;div class="modal-dialog" role="document"&gt;
          &lt;div class="modal-content"&gt;
              &lt;div class="modal-header"&gt;
                  &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;
                  &lt;h4 class="modal-title text-primary"&gt;Login&lt;/h4&gt;
              &lt;/div&gt;
              &lt;div class="modal-body"&gt;
                  &lt;?php echo form_open(); ?&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label class="control-label"&gt;Username:&lt;/label&gt;
                      &lt;input type="text" class="form-control" name="username" id="username" required=""&gt;
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label class="control-label"&gt;Password:&lt;/label&gt;
                      &lt;input type="password" class="form-control" name="password" id="password" required=""&gt;
                  &lt;/div&gt;
                  &lt;?php echo form_close(); ?&gt;
              &lt;/div&gt;
              &lt;div class="modal-footer"&gt;
                  &lt;button type="button" name="submit" id="property_owner_login" class="btn btn-success"&gt;Login&lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Javascript file</strong></p>
  
  <pre><code>var property_owner_login = {
      mode: "Add",
      modal: $("#property_owner_login"),
      add: function () {
          var username = $("#username").val();
          var password = $("#password").val();
          $.ajax({
              url: "/Property",
              type: 'POST',
              data: {username: username, password: password},
              success: function (data) {
                  console.log(data)
                  var obj = JSON.parse(data);
                  //console.log(data.username);
  
                  if (obj.username == 'admin' &amp;&amp; obj.password == 'admin') {
                      window.location.href = 'property/property_owner_detail';
                  } else {
  
                  }
              }
          });
      }
  };
  
  $(document).ready(function () {
      $("#property_owner_login").click(function () {
          if (property_owner_login.mode == "Add") {
              property_owner_login.add();
          }
      });
  });
  </code></pre>