【发布时间】:2015-03-28 08:50:28
【问题描述】:
我的博客(博主)需要一个有效代码才能使用以下字符串获取 YouTube 视频的标题:
“http://gdata.youtube.com/feeds/api/videos/EDV-KMBvMck?v=2&alt=json&prettyprint=true”
(此字符串在 Internet Explorer 中运行良好)
我已经通过了这里找到的各种方法,但没有显示结果。
我想在 td 标签内显示视频的标题。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style>
table#t01 {
width: 100%;
}
table#t01,
th,
td {
border: 1px solid black;
border-collapse: collapse;
text-align: center;
}
</style>
</head>
<body>
<div>
<table id="t01">
<col style="width:50%;">
<col style="width:50%;">
<tr>
<td>
<a href="http://www.youtube.com/embed/EDV-KMBvMck" target="_blank"><img src="https://img.youtube.com/vi/EDV-KMBvMck/default.jpg"" alt="YouTube Icon"></a>
</td>
<td>
<script>
$Video_Id = 'EDV-KMBvMck'
$.getJSON("http://gdata.youtube.com/feeds/api/videos/{$Video_Id}?v=2&alt=json&prettyprint=true", function(json) {
console.log("success");
var items = [];
$.each(json. {
$Video_Id
}, function(key1, val1) {
$Value = val1.key + val1.val
});
echo $Value
})
.done(function() {
console.log("second success");
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
})
.error(function(error) {
console.log(error);
});
</script>
</td>
</tr>
<tr>
<td>
<a href="http://www.youtube.com/embed/yXL7dT7ovEM" target="_blank"><img src="https://img.youtube.com/vi/yXL7dT7ovEM/default.jpg"" alt="YouTube Icon"></a>
</td>
<td>
<script>
$Video_Id = 'yXL7dT7ovEM'
$.getJSON("http://gdata.youtube.com/feeds/api/videos/{$Video_ID}?v=2&alt=json&prettyprint=true", function(json) {
console.log("success");
var items = [];
$.each(json. {
$Video_Id
}, function(key1, val1) {
$Value = val1.key + val1.val
});
echo $Value
})
.done(function() {
console.log("second success");
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
})
.error(function(error) {
console.log(error);
});
</script>
</td>
</tr>
</table>
</div>
</body>
</html>
我想在标题中添加一个函数,该函数会在每次更改 Video_Id 时从 td 标记调用。
【问题讨论】: