I am new to using api's and php. but i am trying to get get a video from within my my project directory using a "new video" button on my simple page. I am not able to get the new video to play. It looks to be a syntax error on my end but i am unsure where i am making the mistake. Also I am using slim v2 framework, if that makes a difference.
<!DOCTYPE html>
<html lang="en">
<head>
<title>WOO</title>
<style type="text/css">
.center {
margin-left: auto;
margin-right: auto;
margin-top: 0px;
width: 70%;
}
h3 {
margin-left: auto;
margin-right: auto;
margin-bottom: 0px;
width: 70%;
font-family: "Lucida Console", Monaco, monospace;
}
</style>
</head>
<body style="background-color: honeydew;">
<h3 id="video-title">Video Example <button id="do-it">new video</button></h3>
<div class="center">
<video id="game" height="600" width="800" controls>
<source src="videos/cyanide.mp4" type="video/mp4" />
You can't play this video
</video>
</div>
<script src="https://code.jquery.com/jquery-2.2.1.min.js"></script>
<script type="text/javascript">
$('#do-it').on('click', function() {
var video = document.getElementsByTagName('video')[0];
var source = video.getElementsByTagName('source')[0];
$.ajax({
'url' : 'php/api.php/getVideo?search=anthony',
'method' : 'GET',
'dataType' : 'json'
}).done(function(data) {
console.log(data);
source.src = data.src;
$('#video-title').text(data.title);
video.load();
})
});
</script>
</body>
</html>
Here is the full html scrpit and below is my php script
<?php
require 'vendor/autoload.php';
$app = new \Slim\Slim();
// If the url matchs a certain word, it'll go to the function specified
$app-> get('/getTest','getTest');
$app-> get('/getVideo','getVideo');
$app->run();
function getTest () {
echo '{"woo":' . json_encode('we made it') . '}';
}
function getVideo() {
// get params from query string
$app = \Slim\Slim::getInstance();
$search = $app->request()->params('search');
// get video data from search
$video = (object)array("title" => "CLUTCH AD", "src" => "videos/anthony_davis.mp4");
echo json_encode($video);
}