前端串js对象数组给php 所用框架thinkphp

WBOY
Release: 2016-06-23 13:39:58
Original
907 people have browsed it

//js 对象<script>    person[]=new Object();    person[0].firstname="Bill";    person[0].lastname="Gates";     person[1].firstname="Bill";    person[1].lastname="Gates";    //将对象转为json字符串    var jsonstr=JSON.stringify(person);    //传递给php    $.post('url',{obj:jsonstr},function(data){},'json');</script>//php 代码public function get_json(){    //获取json字符串    //注意 用thinkphp 框架 最好不要用框架自带的I方法获取数据,因为I方法在过滤字符串的同时会把字符串内部的双引号转义,导致解析json失败 返回null.此时若用json_last_error()函数获取 介绍返回提示,返回值可能是4 表示语法错误。    $str=$_POST['obj'];    //解析json    $str=json_decode($str);}
Copy after login

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!