在PHP代码中,当我使用带有ajax的youtube api时,ajax调用无效。是否有任何代码用于youtube api和ajax。代码我在下面给出。
<div style="float:left; width:520px; height:350px;">
<script type="text/javascript">
var videoId ="http://www.youtube.com/v/<?php echo $video_url;?>";
function $(id) {
return document.getElementById(id);
}
</script>
<script src="http://www.google.com/jsapi"></script>
<script>
google.load("swfobject", "2.1");
</script>
<table>
<tr><td>
<div id="player">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>
<script>
var ytplayer;
var totallength=0;
var duration=0;
function myOnPlayerStateChange(state) {
switch(state) {
case 2: // paused
$.ajax({
url: 'UpdateYoutubeStatus.php',
//data: {'status':'paused'},
success: function(msg){
alert("Ok");
},
error:function(data){
alert("error");
}
});
break;
case 0: // ended
$("out").innerHTML += " ended";
break;
case -1: // unstarted
case 3: // buffering
case 5: // cued
break;
default: // unknown
break;
}
}
function myOnPlayerError(errorCode) {
$("out").innerHTML += " Error occurred: " + errorCode;
}
function onYouTubePlayerReady(playerId) {
ytplayer = ytplayer || $(playerId);
ytplayer.addEventListener("onStateChange", "myOnPlayerStateChange");
ytplayer.addEventListener("onError", "myOnPlayerError");
}
var params = { allowScriptAccess: "always", bgcolor: "#cccccc" };
var atts = { };
swfobject.embedSWF(videoId + "?border=0&enablejsapi=1&playerapiid=" + 'player' + "&version=3", 'player', 400, 350, "8", null, null, params, atts);
</script>
</td></tr>
</table>
我尝试将Youtube API调用和ajax调用隔离到单独的文件中,然后它独立工作。但如果我将Ajax方法和youtube API结合使用,那么就会出现问题。
信息:我将这个youtube播放器从另一个页面加载到Frameset(而不是IFrame)