title: Javascript pass id - view to controller -
body: <p>This is not working in my CodeIgniter function. As I have the id and cannot get that id in my controller function. I am puzzled how to do it in Javascript and Ajax way.</p>
  <p>This is my view script</p>
  <pre><code>&lt;script&gt;
   function delete_img_fn(id)
      { 
        alert(id); // It gives '1','2',etc on clicking every row in table 
        var r=confirm(&quot;Do you want to Delete&quot;);
        if (r==true)
        {
             $.post(&quot;&lt;?php echo site_url('/admincontent/delete_portfolioimg/');?&gt;&quot;, {id:id},
             function(data) {
                  alert(data+&quot;a&quot;);
             }, 'json');
        }
        else
        {
             x=&quot;You pressed Cancel!&quot;;
             alert(x);
        }      
      }
      
  &lt;/script&gt;
  </code></pre>
  <p>and i am trying to send my id through the controller function as follows:</p>
  <pre><code>public function delete_portfolioimg()
   { 
  echo $this-&gt;input-&gt;post('id');exit('I am trying in controller function');
  }
  </code></pre>
  <p>The above is not working.
  I also tried the below code:</p>
  <pre><code> window.location.href = &quot;&lt;?php echo site_url('/admincontent/delete_portfolioimg/'.id);?&gt;'?id=&quot;+id;
  
  window.location.href = &quot;&lt;?php echo site_url('/admincontent/delete_portfolioimg/'.id);?&gt;&quot;;
  </code></pre>
  <p>But neither worked...
  It would also help me if someone guide me how to do in ajax way out!</p>