如何使用javascript、ajax、jquery和mysql自动保存当前视频播放时间?
到目前为止,我的代码如下所示:如何使用javascript、ajax、jquery和mysql自动保存当前视频播放时间?,javascript,jquery,mysql,ajax,video.js,Javascript,Jquery,Mysql,Ajax,Video.js,到目前为止,我的代码如下所示: var vid = document.getElementById("example"); vid.ontimeupdate = function() {myFunction()}; function myFunction() { // Display the current position of the video in a <p> element with id="demo" document.g
var vid = document.getElementById("example");
vid.ontimeupdate = function() {myFunction()};
function myFunction() {
// Display the current position of the video in a <p> element with id="demo"
document.getElementById("timer").innerHTML = vid.currentTime;
var tiempo2=vid.currentTime;
// alert(tiempo2);
}
$(document).ready(function(){
function autoSave()
{
var tiempo = $('#timer').val();
var idvideo = $('#idvideo').val();
alert(tiempo2);
// if(tiempo != '')
// {
$.ajax({
url:"save_time.php",
method:"POST",
data:{tiempo_play:tiempo, id_video:idvideo},
dataType:"time",
success:function(data)
{
if(data != '')
{
$('#idvideo').val(data);
}
$('#autoSave').text("Post save as draft");
setInterval(function(){
$('#autoSave').text('');
}, 3000);
}
});
//}
}
setInterval(function(){
autoSave();
}, 5000);
});
</script>
var vid=document.getElementById(“示例”);
vid.ontimeupdate=function(){myFunction()};
函数myFunction(){
//使用id=“demo”在元素中显示视频的当前位置
document.getElementById(“计时器”).innerHTML=vid.currentTime;
var tiempo2=vid.currentTime;
//警报(tiempo2);
}
$(文档).ready(函数(){
函数autoSave()
{
var tiempo=$('#timer').val();
var idvideo=$('#idvideo').val();
警报(tiempo2);
//如果(tiempo!='')
// {
$.ajax({
url:“save_time.php”,
方法:“张贴”,
数据:{tiempo_play:tiempo,id_video:idvideo},
数据类型:“时间”,
成功:功能(数据)
{
如果(数据!='')
{
$('#idvideo').val(数据);
}
$('#autoSave').text(“后期另存为草稿”);
setInterval(函数(){
$(“#自动保存”).text(“”);
}, 3000);
}
});
//}
}
setInterval(函数(){
自动保存();
}, 5000);
});
首先,我获取视频当前播放时间,并尝试将其传递到我的php文件,以便每5秒将其发布到我的数据库中。问题是,当我试图获取当前时间时,我无法以正确的方式分配当前时间;它是空的,未定义的,它是一个对象,等等
我希望我能正确地解释我自己,这是我第一次使用ajax和jquery,所以我不太确定一切是如何工作的,这也是我第一次在这里发帖,如果你需要更多的细节,请告诉我