Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing a jQuery load() function variable to codeigniter controller
    text
    copied!<p>is there a way to pass a variable to a codeigniter controller using jquery's load() function?</p> <p>currently this is my non working code</p> <p>main.php</p> <pre><code>&lt;input type="hidden" id="url" name="url" value="&lt;?php echo base_url();?&gt;site/pax_dropdown/" /&gt; &lt;input type="hidden" val="2" id="value"&gt; &lt;ul id="result" class="dropdown-menu"&gt; &lt;?php $this-&gt;load-&gt;view("site/pax_dropdown"); ?&gt; &lt;/ul&gt; </code></pre> <p>pax_dropdown.php</p> <pre><code>&lt;li&gt;&lt;a href=""&gt;3&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;4&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;5&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;6&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;7&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;8&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=""&gt;9&lt;/a&gt;&lt;/li&gt; &lt;?php echo $id; ?&gt; </code></pre> <p>script.js</p> <pre><code>var url = $("#url").val(); var val = $("#value").val(); $('#result').load(url,val); </code></pre> <p>controller</p> <pre><code>public function pax_dropdown($id) { $data['id'] = $id; $this-&gt;load-&gt;vars($data); $this-&gt;load-&gt;view("site/pax_dropdown"); } </code></pre> <p>with this code the pax_dropdown.php successfully loads inside the </p> <pre><code>&lt;ul id="result"&gt; </code></pre> <p>in my main.php however my test variable $id cannot be found and says Message: Undefined variable: id am i doing something wrong?</p> <hr> <p>by the way i also tried sending the variable to the controller this way:</p> <p>main</p> <pre><code>&lt;input type="hidden" id="url" name="url" value="&lt;?php echo base_url();?&gt;site/pax_dropdown/2" /&gt; </code></pre> <p>i placed the variable to be passed at the end of the url, which in this case is "2"</p> <p>and it still did not work</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload