ThinkPHP3 一个变态的问题,$this->_post()得到的数据问题
首先:
js设定一个输入框的值
$(“#paramters”).val(“{\”a\”:\”aaaa\”}”);
在后台获取并转json
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Php代码 header("Content-type:text/html;charset=UTF-8"); $paramters = null; if(get_magic_quotes_gpc()){ $paramters = stripslashes($this->_post('paramters')); }else{ $paramters = $this->_post('paramters'); } echo ($paramters); echo '<br>'; $arr = json_decode($paramters,true); var_dump($arr); echo '<br>'; $paramters = $_POST['paramters']; $arr = json_decode($paramters,true); var_dump($arr); |
后台输出:
{“a”:”aaaa”}
NULL
array(1) { [“a”]=> string(4) “aaaa” }
说明:
$paramters = $this->_post(‘paramters’);虽然获得数据看起来是对的,但无法转json
$paramters = $_POST[‘paramters’];这样却没问题的.
所以获取客户端的数据,最好使用php自身提供的.
