I am new to php and trying to implement a small webpage part of a school project. reportBuffering method in video.js file should call bufferingEventLogger method in server.php using Jquery ajax and store the passed values in Database. I am not able to trigger the bufferingEventLogger function. Here's the code for video.js
var video;
$(document).ready(function(){
var timeBuffered = 0;
var timer;
video = $('#main-video')[0];
video.play();
$(video).on("play",function(){
if(timer!=null)
clearInterval(incrementBufferedTime);
});
$(video).on("waiting",function(){
timer = setInterval(function(){
incrementBufferedTime
},1000);
});
function incrementBufferedTime(){
timeBuffered++;
console.log("Buffered time"+timeBuffered);
if(timeBuffered > 5){
reportBuffering()
}
}
function reportBuffering(){
$.ajax({
method: "POST",
url: "server.php",
data:{functionId:'bufferingEventLogger',val0:1,val1:'2016-04-18 16:37:01',val2:'2016-04-18 16:37:02'},
success:function (response) {
console.log(response)
}
});
}
reportBuffering();
});
Below code is for server.php
$id=$_POST['val0'];
$bufferStartTime=$_POST['val1'];
$bufferEndTime=$_POST['val2'];
//bufferingEventLogger($id,$bufferStartTime,$bufferEndTime);
function bufferingEventLogger($id,$bufferStartTime,$bufferEndTime){
$conn = mysqli_connect("localhost", "root", "", "metrics");
$sql = "INSERT INTO buffer_time(id,buffer_start,buffer_end) VALUES $id,'$bufferStartTime','$bufferEndTime')";
echo 'entered';
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
mysqli_close($link);
I have gone through similar questions, but couldn't get it to work. Thanks