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条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?