我正在使用CodeIgniter编写服务器脚本,以将html代码存储到数据库中。我的客户端发送一个包含html字符串的json包:
<table style='width:50%'
但是从我的服务器端我只能从$ this-&gt; 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
我的PHP代码来处理JSON:
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包的方式不同造成的?
答案 0 :(得分:2)
试
$this->input->post()
不是$this->post()
$ _ POST有效,因为那是原始的php函数
答案 1 :(得分:0)
我通过$ _POST [&#39; answer&#39;]替换$ this-&gt; post(&#39; answer&#39;)解决了这个问题。
仍然不知道发生了什么,但它确实有效
答案 2 :(得分:0)
$this->post('answer');
应该是
$this->input->post('answer');