dongyiba8082 2013-09-10 11:14
浏览 76
已采纳

将jQuery load()函数变量传递给codeigniter控制器

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

  • 写回答

3条回答 默认 最新

  • donglisi8644 2013-09-10 12:04
    关注

    Look at this example to pass a variable using jQuery.load() :

    var siteName='example.com';
    $("#result").load(sitename+"/site/pax_dropdown/2", {"variableName": variable});
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?