Home  >  Article  >  php教程  >  ajax与PHP 传参问题

ajax与PHP 传参问题

WBOY
WBOYOriginal
2016-06-06 19:42:30836browse

可以在PHP端把多个参数封装成一个对象。比如 $people['age'] = "21"; $people['gender'] = "male"; $people['phoneNum'] = "12345678"; 然后 echo json_encode($people); json_encode()函数的作用是把$people打包成一个JSON结构的对象。 然后在js端用eval(

可以在PHP端把多个参数封装成一个对象。比如

$people['age'] = "21";

$people['gender'] = "male";

$people['phoneNum'] = "12345678";

然后 echo json_encode($people);

 json_encode()函数的作用是把$people打包成一个JSON结构的对象。

然后在js端用eval()函数将JSON结构解析成一个对象,就可以用obj.age或者obj.phoneNum的形式调用PHP传过来的参数了。

详细的例子可以看这个:

http://www.cnblogs.com/elaron/archive/2010/11/16/1878369.html

Statement:
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
Previous article:php 读取mysql后,jsonNext article:PHP代码源被黑了!