php - jQuery .load 停止嵌入页面的视频/重新加载整个页面

标签 php jquery html reload

我有一个关于使用 jQuery-.load 重新加载 div 的问题。代码:

    <h1>Official Live-Stream</h1>
    <object width="560" height="315" data="http://www.dailymotion.com/embed/video/x10sbxw"></object>
    </br>
    </br>

    <script>
        (function($)
        {
            $(document).ready(function()
            {
                $.ajaxSetup(
                {
                    cache: false,
                    beforeSend: function() {
                        $('#content').hide();
                        $('#loading').show();
                    },
                    complete: function() {
                        $('#loading').hide();
                        $('#content').show();
                    },
                    success: function() {
                        $('#loading').hide();
                        $('#content').show();
                    }
                });
                var $container = $("#liveracingblog");
                $container.load("../live/addon/addon_ticker.php");
                var refreshId = setInterval(function()
                {
                    $container.load('../live/addon/addon_ticker.php');
                }, 30000);
            });
        })(jQuery);
    </script>

    <div id="liveracingblog"></div>

我遇到的问题是,每 30 秒不仅会重新加载 liveracingblog-div,还会重新加载整个页面,这使得嵌入第 2 行的视频停止。

您可以在此处观察问题:http://www.racingblog.de/racingbloglive/ (代码是 Wordpress 页面模板的一部分,但我认为这不重要)

如何解决这个问题?

最佳答案

我查看了该页面,#content div 似乎包含嵌入视频,您在 js 中隐藏和显示了该视频。您只想隐藏和显示 #liveracingblog div

以下更改应该有效:

         $.ajaxSetup(
            {
                cache: false,
                beforeSend: function() {
                    $('#liveracingblog').hide();
                    $('#loading').show();
                },
                complete: function() {
                    $('#loading').hide();
                    $('#liveracingblog').show();
                },
                success: function() {
                    $('#loading').hide();
                    $('#liveracingblog').show();
                }
            });

我还注意到,每 30 秒就会从数据库中提取大量记录,并且由于您使用的是 load() 方法,任何向下滚动的用户都将返回到此 div 的顶部。我建议完全忘记隐藏 div。相反,用 $get 替换 load() 以返回任何新记录(自上次请求以来),然后将这些新记录添加到 #liveracingblog div 中。

无论如何,祝你好运,如果你想对此进行更多说明,请告诉我。阿德里安

关于php - jQuery .load 停止嵌入页面的视频/重新加载整个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17200457/

相关文章:

javascript - 如果表单中出现错误,则提交表单时对话框应保持打开状态

javascript - JQuery 日期选择器预定义日期

javascript - kendoColorPicker 动态创建 - 如何获取元素 id?

html - 在悬停时缩放和向左移动时防止闪烁

html - 为什么在 Chrome 而不是 Firefox 中的这些 block 元素之间有细线间隙/边框

php - 在 jquery 中动态设置按钮文本

php - 使用 CSS 设置 PHP 样式

php - 使用 laravel 连接多个表

javascript - 用变量替换字符串值

css - Bootstrap 2 span6