title: AJAX to open Modal in CodeIgniter
body: <p>I'm creating a "single page" app where I want to load different views in my dashboard
  with AJAX. I'm using jQuery for the AJAX calls. I've created contollers foreach of my views
  (is this considered to be a bad practice? Will it be better to just make one controller with multiple methods for loading all of my views?) 
  and everything is working just fine except the actual modal I need to show with AJAX. </p>
  
  <p>I can preview the response (modal) with my developer tool, but I'm not getting it to show right in my eyes.</p>
  
  <p>At start, this specific modal was included in one of my views where I appended every one of my other views with AJAX,
  but I founded it as bad practice and created a new view for that modal.</p>
  
  <p><strong>So here's my controller to load the view (modal):</strong></p>
  
  <pre><code>&lt;?php
  
      class Add_user extends CI_Controller
      {
  
          public function __construct()
          {
  
              parent::__construct();
              $this-&gt;load-&gt;model('user_model');
              $this-&gt;load-&gt;model('subject_model');
          }
  
          public function index()
          {
  
          $data['subjects'] = $this-&gt;subject_model-&gt;get_all_subjects();
          $data['schools'] = $this-&gt;subject_model-&gt;get_all_schools();
  
          $this-&gt;load-&gt;view('new_user', $data);
          }
      }
  
  ?&gt;
  </code></pre>
  
  <p><strong>Here's the view for the modal (pretty much standard HTML with some CodeIgniter's helper methods):</strong></p>
  
  <pre><code>&lt;?php $this-&gt;load-&gt;helper('form'); ?&gt;
  &lt;?php $attributes = array(
          'id' =&gt; 'add_user_form'
      );
  ?&gt;
  
  &lt;?php echo form_open('users/add_user', $attributes); ?&gt;
  
      &lt;span class="close_form_button_add_user_form"&gt;&amp;times;&lt;/span&gt;
  
      &lt;div class="form_header"&gt;
          &lt;h1&gt;Create New User&lt;/h1&gt;
      &lt;/div&gt; &lt;!-- end of form_header --&gt;
  
      &lt;!-- Message and response elements--&gt;
      &lt;div class="loading_spinner" id="loading_spinner_add_user" style="display:none;"&gt;&lt;/div&gt;
      &lt;div class="login_error" id="new_user_error" style="display:none"&gt;
          &lt;span class="close_error"&gt;&amp;times;&lt;/span&gt;
      &lt;/div&gt;
      &lt;div class="front_success" id="new_user_success" style="display:none"&gt;&lt;/div&gt;
  
  
      &lt;div class="form_row"&gt;
          &lt;div class="sign-pass"&gt;
              &lt;label for="f_name"&gt;Etunimi&lt;/label&gt;
              &lt;input type="text" name="f_name"/&gt;
          &lt;/div&gt;
  
          &lt;div class="sign-pass-again"&gt;
              &lt;label for="l_name"&gt;Sukunimi&lt;/label&gt;
              &lt;input type="text" name="l_name"/&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form_row"&gt;
          &lt;div class="sign-pass"&gt;
              &lt;label for="email"&gt;Sähköpostiosoite&lt;/label&gt;
              &lt;input type="email" name="email"/&gt;
          &lt;/div&gt;
  
          &lt;div class="sign-pass-again"&gt;
              &lt;label for="email_confirm"&gt;Sähköposti uudelleen&lt;/label&gt;
              &lt;input type="email" name="email_confirm"/&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form_row"&gt;
          &lt;label for="phone_number"&gt;Puhelinnumero (valinnainen)&lt;/label&gt;
          &lt;input type="text" name="phone_number" class="full-width" /&gt;
      &lt;/div&gt;
  
      &lt;div class="form_row"&gt;
          &lt;div class="sign-pass"&gt;
              &lt;label for="user_type"&gt;Valitse käyttäjätyyppi&lt;/label&gt;
              &lt;select name="user_type" class="add_user_select" id="select_user_type"&gt;
                  &lt;option value=""&gt;Käyttäjätyyppi&lt;/option&gt;
  
                  &lt;option value="admin"&gt;Hallinto&lt;/option&gt;
                  &lt;option value="moderator"&gt;Hallinto 2&lt;/option&gt;
                  &lt;option value="enduser"&gt;Pääkäyttäjä&lt;/option&gt;
              &lt;/select&gt;
          &lt;/div&gt;
  
          &lt;div class="sign-pass-again"&gt;
              &lt;input type="submit" name="submit_user" value="Luo käyttäjä" class="login_submit" id="submit_user" style="margin: 5px 24px 0px 0px;"/&gt; &lt;/br&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form_row" id="add_user_optional_information"&gt;
          &lt;label for="school"&gt;Choose school&lt;/label&gt;
              &lt;select name="school" class="add_user_select_optional"&gt;
                  &lt;option value=""&gt;School&lt;/option&gt;
                  &lt;?php  foreach($schools as $school) :?&gt;
                  &lt;option value="&lt;?=$school['id']?&gt;"&gt;&lt;?=$school['name']?&gt;&lt;/option&gt;
                  &lt;?php endforeach; ?&gt;
              &lt;/select&gt;
  
  
          &lt;label for="subject"&gt;Choose subject&lt;/label&gt;
              &lt;select name="subject" class="add_user_select_optional" style="margin-bottom: 20px;"&gt;
                  &lt;option value=""&gt;Subject&lt;/option&gt;
                  &lt;?php  foreach($subjects as $subject) :?&gt;
                  &lt;option value="&lt;?=$subject['id']?&gt;"&gt;&lt;?=$subject['name']?&gt;&lt;/option&gt;
                  &lt;?php endforeach; ?&gt;
              &lt;/select&gt;
      &lt;/div&gt;
  &lt;?php echo form_close(); ?&gt;
  </code></pre>
  
  <p><strong>And here's a part of my JS file for the AJAX response:</strong></p>
  
  <pre><code>$(".add_user").on("click", function(e) {
      e.preventDefault();
      var url = $(this).attr("href");
  
          $.ajax({
  
              url: url,
              async: false,
              data: url,
              success: function(data) {
  
              // Here's the part what I'm thinking is wrong
  
              $("form#add_user_form").easyModal({
                  top: 80,
                  autoOpen: true,
                  overlayOpacity: 0.1,
                  overlayColor: "#000000",
                  overlayClose: true,
                  closeButtonClass: "span.close_form_button_add_user_form"
              });
          }           
          });
      return false;
  });
  </code></pre>