我正在写一个网站(这是我第一次没有 java..),所做的很简单。我调用了一个 javascript 函数“changeVideo()”,该函数向 php 页面“GetAVideo.php”发出请求,该页面将 url 返回到随机选择的视频(在我的服务器上的视频文件之间选择)。
昨晚,我可以毫无问题地观看视频,但今天,当我加载我的页面时,由于 GET 请求失败,视频没有加载:“NS_ERROR_FAILURE: Failure xhr_object.send();”
我不明白为什么,这是我的资料来源:javascript:
function changeVideo()
{
console.log("changeVideo path:", path);
var xhr_object = null;
if (window.XMLHttpRequest) // Firefox
xhr_object = new XMLHttpRequest();
else if (window.ActiveXObject) // Internet Explorer
xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
var request = "http://ogdabou.com/php/GetAVideo.php";
console.log("request: ", request);
xhr_object.open("GET", request, false);
xhr_object.send();
console.log("response: ", xhr_object.responseText);
videoPlayer.src(xhr_object.responseText);
videoPlayer.currentTime(0);
videoPlayer.play();
document.getElementById("videoTitle").innerHTML = xhr_object.responseText;
return false;
};
php:
<?php
$dirname = '../videos';
$videoList = array();
$dir = opendir($dirname);
if (count($_GET) > 0)
{
$folders=explode(";", $_GET['folders']);
foreach ($folders as $videoFolder) {
$fullPath = $dirname."/".$videoFolder;
echo "Visiting $fullpath";
$videoList = fillVideoList($fullPath, $videoList);
}
}
else
{
$videoList = fillVideoList($dirname, $videoList);
}
//use join to get the paths.
closedir($dir);
$choosenOne = $videoList[rand(0, count($videoList) - 1)];
$choosenOne = str_replace("../videos/","", $choosenOne);
echo "http://ogdabou.com/videos/".$choosenOne;
?>
<?php
// Fill the videoList with the given folder. Also visit subdirectories.
function fillVideoList($folder, $videoList)
{
$path = $folder;
$folder = opendir($folder);
while($file = readdir($folder)) {
if($file != '.' && $file != '..')
{
$fullPath = "$path/$file";
if (is_dir($fullPath))
{
$videoList = fillVideoList($fullPath, $videoList);
}
else if(pathinfo($fullPath, PATHINFO_EXTENSION) == "webm")
{
$videoList[] = $fullPath;
}
}
}
return $videoList;
}
?>
谢谢 !