我正在使用 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 包的方式之间的差异造成的?