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