0

我有一个表单,经过这么多秒后会自动将表单保存到数据库中(这就是我的意图)

下面的脚本抓取 jQuery AJAX 请求中的值并将其发送到控制器 - 但每当我尝试 var_dump 值时,它似乎无法从序列化数组中工作。当我在 Firefox 中查看 FireBug 但似乎无法打印数组时,我可以看到参数存在 - 谁能解释为什么?

// view logic
var t = setTimeout("autosave()", 10000); 
$.ajax( 
{ 
    type: "GET", 
    url: "/questionnaires/autosave", 
    data: $("form").serialize(), 
    cache: false, 
    success: function(msg) {
        return false;
    }
});

// controller logic
function autosave()
{
    $str = parse_str( $this->input->get_post('form') );
    var_dump($str); // intend to do an insert query here to the db
}
4

1 回答 1

0

您很可能没有query_string在 config.php 中启用。

结果,您将无法GET可靠地使用。您最好的选择是更改type: "GET",type: "POST",.

然后用于$this->input->post()访问 post 变量。您可以从 Codeigniter 文档中参考此信息:

http://codeigniter.com/user_guide/libraries/input.html

$this->input->post()

第一个参数将包含您要查找的 POST 项目的名称:

$this->input->post('some_data'); The function returns FALSE (boolean)

如果您尝试检索的项目不存在。

第二个可选参数允许您通过 XSS 过滤器运行数据。通过将第二个参数设置为布尔值 TRUE 来启用它;

$this->input->post('some_data', TRUE); To return an array of all POST

项目调用没有任何参数。

要返回所有 POST 项目并通过 XSS 过滤器传递它们,请将第一个参数设置为 NULL,同时将第二个参数设置为布尔值;

如果 POST 中没有项目,该函数将返回 FALSE(布尔值)。

$this->input->post(NULL, TRUE); // returns all POST items with XSS
$this->input->post(); // returns all POST items without XSS
于 2012-07-23T16:18:28.113 回答