js里边的对象ajax post到php端直接变成数组了

WBOY
Release: 2016-06-13 11:34:23
Original
753 people have browsed it

js里面的对象ajax post到php端直接变成数组了?

本帖最后由 zhoumengkang 于 2013-09-12 10:03:14 编辑 事先引入了jquery
var str ="{'a':'b','aa':'bb'}";<br />var str2 = eval('('+str+')');<br />var type = typeof(str2);<br />console.log(str);<br />console.log(type);//object<br />console.log(str2);<br />$.post('./bb.php',{'data':str2});
Copy after login

bb.php的代码
$data = $_POST['data'];<br />var_dump($data);
Copy after login

控制台上看返回结果,直接输出为数组了
array(2) {<br />  ["a"]=><br />  string(1) "b"<br />  ["aa"]=><br />  string(2) "bb"<br />}
Copy after login

我一般都是在php端需要json_decode()处理的,这样,不需要解析json格式,直接拿到的是数组了。

虽然一直知道js里对象就类似于php的关联数组,也不明白,这是什么原理呢(js里面的对象ajax post到php端直接变成数组了?)。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template