返回带有路径JSON的项目描述
Return the item description with path JSON
我想在标签<p>
中显示菜单中所选项目的描述,但我在所有html中都返回了一个错误。有人知道我应该使用什么财产吗?
json路径为:data.query.results.channel.item.description
javascript:
$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Frss.cnn.com%2Fservices%2Fpodcasting%2Fac360%2Frss.xml'%20AND%20itemPath%3D%22%2F%2Fchannel%22&format=json&diagnostics=true&callback=?", function (data) {
// Load Titles patch Json
console.log(data.query.results.channel.item);
var titles = data.query.results.channel.item.map(function(item) {
return item.title;
});
var urls = data.query.results.channel.item.map(function(item) {
return item.origLink;
});
var descri = data.query.results.channel.item.map(function(item) {
return item.description;
});
$(".description-podcast p").text(descri);
console.log(titles);
$(".container-list-podcast ul").append('<li>' + titles.join('</li><li>'));
$(".container-list-podcast ul li").each(function(key, value){
var text = $(this).text();
$(this).html('<a href="' + urls[key] + '">' + text + '</a>');
});
// Load Navigation Only Key
a=$('.nav_holder li a').keynav(function() {
return window.keyNavigationDisabled;
});
});
jsfiddle
$(".description-podcast p").html(descri);
http://jsfiddle.net/Cf5QU/8/
每个的说明
var i=0;
$("a").each(function(){if($(this).css("background")=="blue")i=$(this).index();});
$(".description-podcast p").html(descri[i]);
http://jsfiddle.net/Cf5QU/9/
发生这种情况可能是因为服务器错误(HTTP代码!=200)。
你可能想:
$.getJSON(
"[your code]"
).error(function(e, xhr, settings) {
console.log(e, xhr, settings);
});
将$(".description-podcast p").text(descri);
更正为$(".description-podcast p").html(descri);
.text
方法将转义任何html字符,但.html
不会。
相关文章:
- 正在将数据主题添加到所有项目
- 动态地改变“”的URL;添加新项目”;链接使用javascript/jquery
- 如何检查管道中未定义的项目
- 有没有一种方法可以添加相同的项目val=“0”;4〃;到JavaScript中数组的每个对象
- 学生搜索项目jquery/javascript
- 如何获取不属于我项目的上一页的URL
- Brightcove获取/显示HTML中的当前视频标题和描述
- Dojo:访问dijit.form.Select中单击的项目
- 角度的项目列表 ng 重复,ng 单击显示全宽描述
- 我需要为我的朋友在这个项目上提供帮助
- 如何从 HTML 查询中删除项目
- 在Meteor项目中安装并包含npm模块后出错
- 当在Ember中点击一个项目时,我如何将一个活动类添加到项目列表中
- JsFiddle在分叉后描述失败
- 将单击事件添加到附加的项目中
- 通过另一个php应用程序将我的项目推送到Github存储库中
- 在javascript中搜索项目列表的性能
- 返回带有路径JSON的项目描述
- 客户端购物车:在数组中添加两个具有相同描述的项目
- 选择比;选择比;文本框(类别>项目在项目描述)