0

我正在使用 CodeIgniter 编写一个服务器脚本来将 html 代码存储到数据库中。我的客户发送一个包含 html 字符串的 json 包:

<table style='width:50%'

但从我的服务器端我只能从 $this->post() 获取:

<table >

你知道哪里错了吗?


我的完整错误日志:

我来自客户端的 JSON(由 AngularJS 的 $.param 编码):

apikey=superrocket_51f0c7333392f&faqid=31&categoryid=44&question=How+to+format+the+answer+%3F&answer=%3Ctable+style%3D'width%3A50%25%3B'%3E&displayorder=0

我处理 JSON 的 PHP 代码:

function updateFAQs_post(){
    $auth = $this->_auth();
    if ($auth){
        print_r($this->post('answer'));
        $this->load->model('Admin_model');
        $faqid = $this->Admin_model->updateFAQs($this->post('faqid'), $this->post('categoryid'), $this->post('question'), $this->post('answer'), $this->post('displayorder'));
        $response = array('success' => 'update done', 'faqid' => $faqid, 'index' => $this->post('index'));
        $this->response($response, 200);
    }
}

我从服务器得到的:

<table >{"success":"update done","faqid":null,"index":false}

faqid 和 index = null 是预期的。它与错误无关。

我认为错误是由于 JavaScript 编码方式和 PHP 解码 JSON 包的方式之间的差异造成的?

4

3 回答 3

2

尝试

$this->input->post()

不是$this->post()

$_POST 有效,因为那是原始的 php 函数

于 2013-07-25T08:34:36.547 回答
0

我通过用 $_POST['answer'] 替换 $this->post('answer') 解决了这个问题。

仍然不知道发生了什么,但它有效

于 2013-07-25T08:32:04.023 回答
0
$this->post('answer');

应该

$this->input->post('answer');
于 2013-07-25T08:48:05.100 回答