我用jQuery中的load方法获得json数据,请问json数据到底放在哪了?load返回值是吗?如何处理?谢谢!

[复制链接]
查看11 | 回复5 | 2011-8-24 04:31:03 | 显示全部楼层 |阅读模式
代码如下:htmlhead/headscripttype=\"text/javascript\"src=\"jquery.js\"/scriptscripttype=\"text/javascript\"$(document).ready(function(){$(\'#aa\').load(\'profile.php\');});/scriptbodydivid=\"aa\"qq/div/body/html----------------------------------------------------profile.php?php$em=rand(10,100);$arr=array(\'email\'=$em,\'website\'=\'http://www.okajax.com\',);$json_string=json_encode($arr);echo$json_string;?
回复

使用道具 举报

千问 | 2011-8-24 04:31:03 | 显示全部楼层
json加载完成后就显示在div里了呀正常的呀帮你测试过了你想要什么样的效果?追问我想要获得数据,然后做其他操作用。怎么弄啊?
回复

使用道具 举报

千问 | 2011-8-24 04:31:03 | 显示全部楼层
那就不要用load这个方法呀用ajax请求呀$.get(\"profile.php\",function(data){//data就是profile.php返回的值,但会被jquery包装成json格式,所以data是一个json对象,可直接使用$(\"#aa\").html(data.website);},\"json\");
回复

使用道具 举报

千问 | 2011-8-24 04:31:03 | 显示全部楼层
$.ajax({type:\"post\",dataType:\"json\",url:\"profile.php\",data:\"r=\"Math.random(),success:function(msg){$(\"#aa\").html(msg.website);}});这样是不是会好些?追问谢谢。但是我想获得profile.php中的数据。php里面的那个rand我是假设为数据库中的数据.
回复

使用道具 举报

千问 | 2011-8-24 04:31:03 | 显示全部楼层
php里数据怎么查询还是跟平常查询一样返回的数据会给success:function(msg)的msg
回复

使用道具 举报

千问 | 2011-8-24 04:31:03 | 显示全部楼层
$.ajax({type:\"post\",dataType:\"json\",url:\"profile.php\",data:\"r=\"Math.random(),success:function(msg){$(\"#aa\").html(msg.website);}});这个才是正道或者用jQuery.get或者jQuery.post,不过都是jQuery.ajax的变种
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行