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端直接变成数组了?)。
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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31