Codeigniter:将值从jquery传递给控制器

时间:2012-08-12 14:50:04

标签: codeigniter

我决定将我的问题分成几部分,以便更容易理解:

第一个问题是:

我有相互依赖的选择列表,所以我将使用jquery

我有这个片段,它会让我获得所选选项的ID:

    //jquery code for source list
    $(document).ready(function(){
    $('#f_state').change(function() {
      if ($(this).val()!='') {
        $("#f_city").load("./controller/control_form.php",{pais_id: $(this).val()});
      }
    // or should I use something like this instead..

var post_url = "./controllers/control_form/" + $(this).val();

but still dont know how to fetch at the controller
        });

    });

但..我实际上是如何将它发送给控制器的?还是从其他角度来看?如何从控制器中检索它?我已经完成了CI场景,但是在codeigniter中..不知道。

问题是,如果我设法在控制器上抓取它,我可以将该索引传递给模型。该模型将执行sql查询并将一个数组返回给控制器,然后我将它打印回视图以填充第二个下拉列表。

谢谢

问候

A

1 个答案:

答案 0 :(得分:0)

.load()中,您已经将数据变量传递给函数,该函数是要传递给服务器的数据。 Reading the documentation

  

如果数据作为对象提供,则使用POST方法;否则,假设GET。

由于您传递的是对象,因此只需从Codeigniter中获取POST数据即可。您可以在标题使用POST,COOKIE或SERVER数据部分的documentation on the Input Class上阅读此内容。但基本上你现在可以

$pais_id = $this->input->post('pais_id', TRUE);
相关问题