各位新年快乐,俺把俺写的东西拿出来秀秀,希望大家可以指点一下.
原文出处:http://hi.baidu.com/tangtou/blog/item/603a24384674b120b8998f1f.html
需要用到的文件有:
ajax1.js 在本博客的另一篇文章里,点这里查看它
json.js(请到网上下载 http://www.json.org/)
json.class.php (请到网上下载 http://www.json.org/)
ajax.htm
var param=’str={"name":"杨庆荣","age":24}’;
//param=encodeURIComponent(param);
url="ajax.php";
ajax_post(url,param,back); //当用ajax_post时,如果用encodeURIComponent(param);会得到错误结果
function back(res)
{
var obj=res.parseJSON(); //使用的是json.js自定义的方法
alert("Name:"+obj.name+",age:"+obj.age);
}
ajax.php
//header("Content-Type:type=text/html;charset=gb2312");
require_once(’json.class.php’); //这个类请到网上去下载
$json = new Services_JSON(); //创建一个实例
$str=$_POST["str"];
$str=stripslashes($str);$str=stripslashes($str);
$obj=$json->decode($str);
$name=$obj->name;
$age=$obj->age;
class Student
{
var $name;
var $age;
function Student($name,$age)
{
$this->name=$name."_From Server";
$this->age=$age."_From Server";
}
}
$stu=new Student($name,$age);
$value=$json->encode($stu); //把$p1转为json字符串
print_r($value);
?>
人打赏
0人 点赞
主帖获得的天涯分:0
举报 |
楼主
|
楼主发言:1次 发图:0张 | 添加到话题 |
181

被折叠的 条评论
为什么被折叠?



