通过ajax请求一个页面 取得返回的json数据
代码如下<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$.ajax({
url:'xxxxxxxxxxxxx',
data:{'short_name':'xxx','threads':'0'},
success:function(data){
//这里开始处理返回的数据
}
})
</script>
请求的url直接打开内容如下
{
"response": {
"4": {
"thread_id": "xxx",
"channel_key": null,
"thread_key": "4",
"comments": 0,
"reposts": 0,
"likes": 0,
"weibo_reposts": 0,
"qqt_reposts": 0
}
},
"options": {
"comments_zero": "暂无评论",
"comments_one": "1条评论",
"comments_multiple": "{num}条评论"
},
"code": 0
}该怎么处理得到 response 下面的comments的值? 不会用javascript操作json 一碰到这个就晕
代码如下<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$.ajax({
url:'xxxxxxxxxxxxx',
data:{'short_name':'xxx','threads':'0'},
success:function(data){
//这里开始处理返回的数据
}
})
</script>
请求的url直接打开内容如下
{
"response": {
"4": {
"thread_id": "xxx",
"channel_key": null,
"thread_key": "4",
"comments": 0,
"reposts": 0,
"likes": 0,
"weibo_reposts": 0,
"qqt_reposts": 0
}
},
"options": {
"comments_zero": "暂无评论",
"comments_one": "1条评论",
"comments_multiple": "{num}条评论"
},
"code": 0
}该怎么处理得到 response 下面的comments的值? 不会用javascript操作json 一碰到这个就晕
解决方案 »
- document write方法如何传递参数?
- 鼠标滑轮
- 请教客户端JS如何用POST方式提交数据(注意是JS提交数据,不是用JS做表单验证),并伪造来路?
- 这代码是如何实现的?
- 求http://bt1.btchina.net站点中鼠标放到电影名称上出来title效果的代码!!
- 这个预定义的右键菜单怎么处理?在线等,急!!
- 如何把第一个页面的信息传递到第二个页面,并进行判断?(菜鸟问题)
- 请教这个怎么写
- 诶呀妈啊,这到底是咋回事啊?
- * * * * 如何控制当前窗口的风格,如没有工具栏,菜单栏等。 * * * *
- 求一个jquery幻灯片教程
- 怎样给jqgrid中的特定行显示特定颜色?怎样在单元格中增加超链接?
alert( data.options.comments_zero )
},"json")
<script type="text/javascript">
$.ajax({
url:'xxxxxxxxxxxxx',
data:{'short_name':'xxx','threads':'0'},
dataType: 'json',
success:function(data){
//这里开始处理返回的数据
}
});
</script>
<script type="text/javascript">
$.ajax({
url:'xxxxxxxxxxxxx',
data:{'short_name':'xxx','threads':'0'},
dataType: 'json',
success:function(data){
//这里开始处理返回的数据
}
});
</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$.ajax({
url:'http://api.duoshuo.com/threads/counts.json',
data:{'short_name':'zhidemaide','threads':'10'},
dataType: 'json',
success:function(data){
//var x = eval("("+data+")");
alert(data.options.comments_zero)
//alert(x.options.comments_zero)
}
})
</script>求再帮忙看看吧..试了半天不行了...
<script type="text/javascript">
$.ajax({
url:'xxxxxxxxxxxxx',
data:{'short_name':'xxx','threads':'0'},
dataType: 'json',
success:function(data){
//这里开始处理返回的数据
}
});
</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$.ajax({
url:'http://api.duoshuo.com/threads/counts.json',
data:{'short_name':'zhidemaide','threads':'10'},
dataType: 'json',
success:function(data){
//var x = eval("("+data+")");
alert(data.options.comments_zero)
//alert(x.options.comments_zero)
}
})
</script>求再帮忙看看吧..试了半天不行了...
调试一下脚本,看返回的data到底是什么数据
alert(data.response[4].comments)
一开始在firebug下的网络里看不到返回数据 修改成如下代码可以看到返回的数据了
但是控制台里报错 SyntaxError: invalid label 求解刚学js没多久 希望大神帮忙费心看看
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$.ajax({
url:'http://api.duoshuo.com/threads/counts.json',
data:{'short_name':'zhidemaide','threads':'10'},
dataType: 'jsonp',
jsonp:'callback',
success:function(data){
alert(11);
}
})</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$.ajax({
type:'get',
url:'http://api.duoshuo.com/threads/counts.json',
data:{'short_name':'zhidemaide','threads':'10'},
dataType: 'json',
success:function(data){
alert('11');
}
});
zhidemaide这个是你的域名?
本地网站都试过 都不行
另外
dataType: 'jsonp',
jsonp:'callback',
不用这两句的话 好像压根不反回数据
如果dataType=json,哪么连接地址是:http://api.duoshuo.com/threads/counts.jsonshort_name是你在doushuo申请的二级域名,你的ajax请求文件必需放在:二级域名.doushuo.com绑定的网站