Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php jplayer ajax使用timeupdate多次运行_Php_Ajax_Jplayer - Fatal编程技术网

Php jplayer ajax使用timeupdate多次运行

Php jplayer ajax使用timeupdate多次运行,php,ajax,jplayer,Php,Ajax,Jplayer,我试图将currentTime、duration和currentPrecentAbsolute值发送到一个php页面,该页面获取这些变量,并使用ajax将它们存储到数据库中。我在暂停事件上工作得很好,但是当我尝试使用timeupdate时,会收到多个呼叫 我希望能够在currentPercentAbsolute达到25%、50%和75%时自动发送数据。我知道问题是什么,只是不知道如何解决。不同浏览器的时间更新速度是不同的,我相信默认值大约是250ms。因此,虽然我的百分比是25%、50%或75%

我试图将currentTime、duration和currentPrecentAbsolute值发送到一个php页面,该页面获取这些变量,并使用ajax将它们存储到数据库中。我在暂停事件上工作得很好,但是当我尝试使用timeupdate时,会收到多个呼叫

我希望能够在currentPercentAbsolute达到25%、50%和75%时自动发送数据。我知道问题是什么,只是不知道如何解决。不同浏览器的时间更新速度是不同的,我相信默认值大约是250ms。因此,虽然我的百分比是25%、50%或75%,但ajax将继续运行。大约4次(每秒4*250ms)。当然,只有当视频长度大约为100秒时,才会出现这种情况。如果它是200秒长,currentPercentAbsolute将保持这些百分比整整一秒钟,运行我的ajax 8次

所以最终我的问题是,做我正在尝试的事情的更好方法是什么。另一方面,我还想实现

$(window).unload(function(){my ajax call in here});
为了能够在用户关闭窗口而不完成视频时获取相同的统计信息。我让它工作,但遇到了同样的问题。它在timeupdate的每次迭代中运行。非常感谢您的任何帮助

我的时间更新代码

timeupdate: function (event) {
    var totaltime = Math.floor(event.jPlayer.status.duration);
    var currenttime = Math.floor(event.jPlayer.status.currentTime);
    var percent = Math.floor(event.jPlayer.status.currentPercentAbsolute);                  

    if(percent == '25'){
        $('#timeNow').html(currenttime);
        $('#percentNow').html(percent); 
        $.ajax({
            type: 'POST',
            url: 'teststats.php',
            data : {timeWatched : currenttime, percentWatched : percent, totalTime : totaltime},
            success : function(data) { }
        });                     
    }
    if(percent == '50'){
        $('#timeNow').html(currenttime);
        $('#percentNow').html(percent);
        $.ajax({
            type: 'POST',
            url: 'teststats.php',
            data : {timeWatched : currenttime, percentWatched : percent, totalTime : totaltime},
            success : function(data) { }
        });                         
    }
    if(percent == '75'){
        $('#timeNow').html(currenttime);
        $('#percentNow').html(percent);
        $.ajax({
            type: 'POST',
            url: 'teststats.php',
            data : {
                timeWatched : currenttime, percentWatched : percent, totalTime : totaltime},
            success : function(data) { }
        });                         
    }
},

我解决了这个问题。 我声明了3个全局变量,然后

if((百分比='25')&&(!a)){

设定

a=true;

在if语句中

还是遇到问题

timeupdate: function(event) {
    var totaltime = Math.floor(event.jPlayer.status.duration);
    var currenttime = Math.floor(event.jPlayer.status.currentTime);
    var percent = Math.floor(event.jPlayer.status.currentPercentAbsolute);  

    $(window).blind('beforeunload', function() {
        if(!d){
            d = true;
            $('#timeNow').html(currenttime);
            $('#percentNow').html(percent);
            $('#totalTime').html(totaltime);                            
            $.ajax({
                type: 'POST',
                url: 'teststats.php',
                data : {
                    timeWatched : currenttime, 
                    percentWatched : percent, 
                    totalTime : totaltime
                },
                success : function(data) { }
            });
        }
    });
}
也许它正在做它应该做的事情。 所有3个变量(CurrentTime、percent和totaltime)都被踢出为0。我不确定当我试图关闭浏览器窗口或导航到另一个url时,jplayer是否会清除timeupdate中的值。有人对此有想法吗?谢谢