title: AJAX call to CodeIgniter controller with parameter
body: <p>I know how <code>AJAX</code> call to <code>CodeIgniter</code> is working.</p>
  
  <p><strong><em>Edit for suggested answer</em></strong></p>
  
  <blockquote>
    <p>I tried <code>redirection</code> as a possible solution to my problem. I am not asking it as question. I am having problem passing parameter through URL and reusing view containing <code>ajax post call</code>. Also I am not aware how to post single value <code>state_id</code> which is already part of <code>new_admission</code> form.</p>
  </blockquote>
  
  <p>I am loading <code>city names</code> for <code>state_id</code> of <code>branch</code> dynamically on <code>$(document).ready()</code></p>
  
  <p>When I call <code>load_city()</code> from <code>admission()</code> it works perfect.</p>
  
  <p><code>XHR</code> for <code>load_city</code> goes like:</p>
  
  <blockquote>
    <p>localhost/project_folder/controller/load_city</p>
  </blockquote>
  
  <p>But when I try <code>edit_admission($studentId)</code> it loads <code>admission_view</code> recursively inside <code>&lt;div id="city"&gt;&lt;/div&gt;</code>.</p>
  
  <p><code>XHR</code> for <code>load_city</code> goes like:</p>
  
  <blockquote>
    <p>localhost/project_folder/controller/edit_admission/load_city</p>
  </blockquote>
  
  <p>Here <code>load_city</code> is considered as parameter and <code>edit_admission()</code> is called recursively.</p>
  
  <p>Controller:</p>
  
  <pre><code>public function load_city()
      {
      //load cities to $data from model 
      $this-&gt;load-&gt;view('city_view', $data);
      }
  
  public function admission()
      {
      //load init data for admission view from model 
      $this-&gt;load-&gt;view('admission_view', $data);
      }
  
  public function edit_admission($studentId)
      {
      //load init data for admission view from model 
      $this-&gt;load-&gt;view('admission_view', $data);
  
      }
  </code></pre>
  
  <p><code>AJAX</code> code:</p>
  
  <pre><code>function get_city() {
      var parameters = {}; //instantiate the array
      parameters['state_id'] = state_id;
  
      $('#divcity').load('load_city', parameters, function (data) {
          $('#city').combobox();
          //code
      });
  
  };
  </code></pre>
  
  <p><code>load_city</code> view:</p>
  
  <pre><code>&lt;?php
      echo '&lt;select class="'.'form-control chzn-select col-lg-8 required'.'" id="'.'city'.'" name="'.'city'.'"&gt;';
      echo '&lt;option&gt;&lt;/option&gt;';
      foreach ($init_city['city_names'] as $row)
      {
          echo '&lt;option value="'.$row-&gt;city_id.'"&gt;' .$row-&gt;city_name.'&lt;/option&gt;';
      }
      echo '&lt;/select&gt;';
  ?&gt;
  </code></pre>
  
  <p><code>admission_view</code>:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
      &lt;label class="control-label col-lg-4"&gt;City&lt;/label&gt;
  
      &lt;div class="col-lg-8" id="divcity" name="divcity"&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong><em>I tried</em></strong></p>
  
  <pre><code>public function edit_admission($studentId)
      {
      if(intval($studentId) &gt; 0){
          //load init data for admission view from model
          $this-&gt;load-&gt;view('admission_view', $data);
      } else if($studentId == 'load_city'){
          //not passing post data to load_city()
          redirect('branch/load_city');
      }
  
  }
  </code></pre>
  
  <p>Above code is not passing post data to <code>load_city()</code>.</p>
  
  <p>Also, I tried adding bellow code in <code>routes.php</code></p>
  
  <pre><code>$route['edit_admission/load_city'] = 'load_city';
  </code></pre>
  
  <p>I did not get any success in both cases.</p>