Hello Guys我正在尝试使用Jquery动态绑定内容。我在stackoverflow网站上进行了很多讨论 例如How to insert metatag without using jquery append?
以下是我尝试过的代码。我不知道我做错了什么。任何帮助都会受到启发。
<head>
<meta property="og:description" content="sdgds"/>
<meta property="og:title" content="sfsfds"/>
<meta property='og:image' content="http://i1.ytimg.com/vi/v9ao-fGMVz8/maxresdefault.jpg" />
<meta property='og:video' content="http://abcd.azurewebsites.net/api/Video/?video_id=1" />
<meta property="og:video:type" content="application/x-shockwave-flash" />
<meta property="og:video:width" content="1920" />
<meta property="og:video:height" content="1080" />
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
$(document).ready(function() {
var first = getUrlVars()["id"];
$.ajax({
type: "Get",
url: 'http://abcd.azurewebsites.net/api/Video/?video_id=1',
success: function (data) {
alert("Hello");
var tv_main_channel = $('#tv_main_channel');
data="http://abcd.azurewebsites.net/Content/movie.mp4";
tv_main_channel.attr("src", data);
var video_block = $('#video');
video_block.load();
$('meta[name=og\\:description]').attr('content', "This is des");
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log(JSON.stringify(XMLHttpRequest));
}
});
});
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
</script>
</head>
答案 0 :(得分:1)
您使用的jquery版本不适合这样做。使用较新的版本。
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0-rc1/jquery.js"></script>