首先:
js设定一个输入框的值
$("#paramters").val("{\"a\":\"aaaa\"}");
在后台获取并转json
后台输出:
{"a":"aaaa"}
NULL
array(1) { ["a"]=> string(4) "aaaa" }
说明:
$paramters = $this->_post('paramters');虽然获得数据看起来是对的,但无法转json
$paramters = $_POST['paramters'];这样却没问题的.
[b][color=red]所以获取客户端的数据,最好使用php自身提供的[/color][/b].
js设定一个输入框的值
$("#paramters").val("{\"a\":\"aaaa\"}");
在后台获取并转json
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'];这样却没问题的.
[b][color=red]所以获取客户端的数据,最好使用php自身提供的[/color][/b].