如何解决如何使用javascript,ajax,jquery和mysql自动保存视频的当前播放时间?
到目前为止,我的代码如下:
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>
首先,我获得了视频的当前播放时间,并尝试将其传递到我的php文件,以便每5秒将其发布到我的数据库中。问题是自从尝试获取当前时间以来,我一直无法正确地通过当前时间。它是空的,未定义的,是一个对象等。
我希望我能正确地解释自己,这是我第一次使用ajax和jquery,所以我不太确定一切正常,这也是我第一次在这里发布,所以如果您需要更多详细信息,请告诉我。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。