【问题标题】:How can I send a JS variable to PHP function in Codeigniter? [duplicate]如何将 JS 变量发送到 Codeigniter 中的 PHP 函数? [复制]
【发布时间】:2018-10-22 19:58:14
【问题描述】:

我想将一个变量从 JS 脚本传递给 CI 控制器上的 PHP 函数。我试过这样做

$.post(base_url+'Controller/function/', {id_formula:id_formula});

但我仍然收到 CodeIgniter 错误

Message: Missing argument 1 for Controller::function()

你能帮我解决吗?请

【问题讨论】:

    标签: javascript php codeigniter


    【解决方案1】:

    那是因为你的控制器可能看起来像这样:

    function function($id_formula)
    {
        ...
    }
    

    但您实际上并没有将“id_formula”作为 URL 获取,而是作为帖子传递。 将其更改为:

    function function()
    {
        $id_formula = $this->input->post('id_formula');
    }
    

    【讨论】:

      猜你喜欢
      • 2016-01-13
      • 1970-01-01
      • 1970-01-01
      • 2012-11-23
      • 1970-01-01
      • 1970-01-01
      • 2018-12-04
      • 2014-03-17
      • 1970-01-01
      相关资源
      最近更新 更多