dongque6377 2014-08-17 22:09
浏览 29

重新加载页面包括每30秒或用户提交表单时

I have a PHP page with a lot of includes which make up various parts of the page for a video website.

I have a comments section which submits information into a database (Which works fine). But I need to make it so when this is done only the included page/div refreshes.

This is the PHP:

<form id="song-comment-form">
    <input type="hidden" value="<?=$rSong->id?>" class="song-id">
    <textarea class="editor" id="song-comment-textarea"></textarea><br>
    <input type="submit" value="Submit"><input type="button" value="Cancel" id="hide-song-comment-form">
    <hr>
</form>
<div id="player-song-comments">
    <?php $showComments?>
</div>

Here is my attempt at doing it with Javascript:

<script>

var $comments = $("#player-song-comments");
setInterval(function () {
    $comments.load("/template/sections/player_comments.php #player-song-comments");
}, 30000);

</script>

This should reload just the comments section but instead, everything from this point onwards goes blank.

How it looks now when I press submit: enter image description here

When I reload that page manually:

enter image description here

I don't want the whole page to refresh because it contains a video.

How can I make just that Refresh after submit is pressed OR every 30 seconds?

UPDATE: I have tried using JQuery to execute this. I'm getting an error:

Fatal error: Call to a member function query() on a non-object in /home/content/58/12052758/html/template/sections/header.php on line 42

    <script> 
        /*wait for the DOM to be loaded 
        $(document).ready(function() { 
            // bind 'myForm' and provide a simple callback function 
            $('#song-comment-form').ajaxForm(function() { 
                alert("Thank you for your comment!"); 
            }); 
        }); */   //THIS IS LINE 42
        $(document).ready(function() { 
        var options = {
            url: 'template/sections/player_comments',
            target: '#player-song-comments', // target element(s) to be updated with server response
            type: 'post' // 'get' or 'post', override for form's 'method' attribute
        }; 

    // bind form using 'ajaxForm' 
    $('#song-comment-form').ajaxForm(options); 
            $(document).ready(function() { 
            // bind 'myForm' and provide a simple callback function 
            $('#song-comment-form').ajaxForm(function() { 
                $("#player-song-comments").load('template/sections/player_comments.php');
                alert("Thank you for your comment! The site is currently in maintenance and the comment won't show until you revisit this video"); 
            }); 
        }); 
}); 
    </script> 

For those interested. Here is the whole page: http://pastebin.com/c0kQ3tGp

  • 写回答

2条回答 默认 最新

  • dounayan3643 2014-08-17 22:52
    关注

    You seems to load comments in PHP and as far as I know, PHP is only parsed once.

    The simplest workaround I know is to use an iframe that you would refresh, but I'm not sure this is a good practice tho.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?