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条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥30 关于#c++#的问题:用C++编程实现主存-Cache地址映射(附运行成功截图+注释)
      • ¥25 接口/特征方法的异常错误返回如何判断是否需要设计
      • ¥40 代码+预测分析,文件私信发哦(价格可商量)
      • ¥15 GAMES101 HW1 无法定义
      • ¥15 pycharm不管允许什么代码都出错,都会出现下面的情况。
      • ¥15 boost::integrate的用法
      • ¥20 51单片机输出pwm时无法调节频率,如何解决?
      • ¥15 DSP28335 AD采集正弦波
      • ¥50 pwwinauto调式修改
      • ¥30 关于#单片机#的问题:单片机基于51单片机开发计时器,使其实现以下功能:(1)开发板上四个独立按键分别控制计时器的启停、计时器的复位(按下计时值归零)、计时位切换、计时时间的递增