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

将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

图片转代码服务由CSDN问答提供 功能建议

有没有办法使用jquery的load()函数将变量传递给codeigniter控制器? \ n

目前这是我的非工作代码

main.php

 &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; 
   
 
 

pax_dropdown.php

 <代码>&LT;李&GT;&LT;一个 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; 
   
 
 

script.js

  var url = $(“#url”)。  val(); 
var val = $(“#value”)。val(); 
 $('#result')。load(url,val); 
   
 \  n 

controller

  public function pax_dropdown($ id)
 {
 $ data ['id'] = $ id; 
 $ this-&gt; load  - &gt; vars($ data); 
 $ this-&gt; load-&gt; view(“site / pax_dropdown”);  
 <
   
 
 

使用此代码,pax_dropdown.php成功加载到

 &lt; ul id =  “结果” &GT;  
   
 
 

在我的main.php中但是找不到我的测试变量$ id并说消息:未定义变量:id am我做错了什么?


顺便说一下,我也尝试以这种方式将变量发送到控制器:

main &lt; input type =“hidden”id =“url”name =“url”value =“&lt;?php echo base_url();?&gt; site / pax_dropdown / 2”/&gt;

我将变量放在url的末尾,在本例中为“2”

它仍然无法正常工作

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题