title: Passing a variable into javascript, codeigniter
body: <p>I am not able to pass a variable from Codeigniter's view to controller and then model that shoots the query that is required to fetch the data from database.</p>
  
  <p>here's my Controller(snippet):</p>
  
  <pre><code>public function read() {
          echo json_encode( $this-&gt;random_model-&gt;getAll() );
  }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code> public function getAll() {
  
      $id = $this-&gt;input-&gt;post('id');
              $id = intval( $id );
     // print_r($sg_id);
  
    //  var_dump($sg_id);
  
  
      $query = $this-&gt;db-&gt;where('id',$id)-&gt;limit( 100 )-&gt;get( 'table_name' );
  
  
  
      if( $query-&gt;num_rows() &gt; 0 ) {
          return $query-&gt;result();
      } else {
          return array();
      }
  }
  </code></pre>
  
  <p>I'm sending the "$id" from another function :</p>
  
  <pre><code>function test1()
  {
  
      $blaa['id'] = $this-&gt;input-&gt;post('id');
  
      if ($query = $this-&gt;model_name-&gt;getAll($blaa)) 
      {
          $blaa['records'] = $query;
      }
  
      //$this-&gt;model_name-&gt;getAll($blaa);
      $this-&gt;load-&gt;view('view_name', $blaa);
  
  }
  </code></pre>
  
  <p>this is the test1 view:</p>
  
  <pre><code>&lt;?php $attributes = array("class" =&gt; "", "id" =&gt; "", "name" =&gt; "");
  
     echo form_open("test/test1/", $attributes);?&gt;
  
  &lt;input type="text" id="id" name="id" &gt;
  
  &lt;?php echo form_submit('submit', 'Submit')?&gt;
  
      &lt;?php echo form_close(); ?&gt;
  </code></pre>
  
  <p>this is the view_name that shows all the data, I'm using dataTables.:</p>
  
  <p>All.js that is rendered in the view_name (read data snippet):</p>
  
  <pre><code>var readUrl   = 'index.php/controller_name/read'
  
  function readUsers() {
  //display ajax loader animation
  $( '#ajaxLoadAni' ).fadeIn( 'slow' );
  
  $.ajax({
      url: readUrl,
      dataType: 'json',
      success: function( response ) {
  
          for( var i in response ) {
              response[ i ].updateLink = updateUrl + '/' + response[ i ].id;
              response[ i ].deleteLink = delUrl + '/' + response[ i ].id;
          }
  
          //clear old rows
          $( '#records &gt; tbody' ).html( '' );
  
          //append new rows
          $( '#readTemplate' ).render( response ).appendTo( "#records &gt; tbody" );
  
          //apply dataTable to #records table and save its object in dataTable variable
          if( typeof dataTable == 'undefined' )
              dataTable = $( '#records' ).dataTable({"bJQueryUI": true});
  
          //hide ajax loader animation here...
          $( '#ajaxLoadAni' ).fadeOut( 'slow' );
      }
  });
  </code></pre>
  
  <p>The results that I get are only of the data having the id "0" , no matter which value I send through the test controller.</p>