$.ajax({
url:'./11.php',
data:{name:'zhang',age:5},//发送数据类型
dataType:'json',//返回数据格式
success:function(msg){
alert(msg);
alert(msg.city);//获取对象内容
}
url:'./11.php',
data:{name:'zhang',age:5},//发送数据类型
dataType:'json',//返回数据格式
success:function(msg){
alert(msg);
alert(msg.city);//获取对象内容
}
})
//11.php ->>url:'./11.php',
<?php
$arr=array('city'=>'山东','mian'=>'960');
echo json_encode($arr);
?>
本文介绍了一个使用Ajax从服务器请求JSON数据的例子。通过发送包含特定参数的数据包到指定URL (11.php),服务器响应一个包含城市名和面积的JSON对象。客户端接收到此对象并读取其属性。

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



