Javascript Http Get Request error : NS_ERROR_FAILURE
I'm writting a website (it's my very first without java..) and what is
done is simple. I call a javascript function "changeVideo()" that make a
request to a php page "GetAVideo.php" which returns the url to a randomly
choosen video (choosen between videos files on my server).
Last night, i could watch videos without problem but today, when i load my
page, the video is not loaded because the GET request fails :
"NS_ERROR_FAILURE: Failure xhr_object.send();"
I can't understand why, here are my sources : 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";
/*if (path.length > 0)
{
request = request + "?folders=";
for (var i = 0; i < path.length ; i++)
{
request = request + path[i] + ";";
}
}*/
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;
}
?>
Thank you !
No comments:
Post a Comment