0

伙计们,我仍然在这里学习,所以如果我的代码很乱,请原谅我的代码。我有 3 个单独的页面,如下
所示: AccountView.php---显示数据的位置:

                      <div class="panel-body">
                        <div id="opentasks">
                        <!-- view Open tasks -->
                            <?php $task= new acct; echo $task->accountActiveTasks()?>
                        </div>
                        <!-- end view open tasks -->
                        <!-- start adding quick task -->
                          <div class="chat-form">
                             <!--  <form method="post" action="addTask.php"> -->
                              <div class="input-cont ">
                                  <input type="text" class="form-control col-lg-12" placeholder="Add a quick Task..." name ="quicktask" id="quicktask">
                              </div>
                              <div class="form-group">
                                  <div class="pull-right chat-features">
                                      <a href="javascript:;">
                                          <i class="icon-camera"></i>
                                      </a>
                                      <a href="javascript:;">
                                          <i class="icon-link"></i>
                                      </a>
                                      <input type="submit" class="btn btn-danger" name="AddTask" value="Add" onclick="add_quick_task()">


                                      <input type="hidden" name="acct" id="acct" value="<?php echo $_REQUEST['acctname']?>">
                                      <input type="hidden" name="user" id="user" value="<?php $username = $_SESSION['username']; echo $username?>"> 
                                  </div>
                              </div>

tasks.js --> 从 AccountView.php 获取一个输入

function add_quick_task(){
            var xmlhttp;
            if (window.XMLHttpRequest) {

                xmlhttp = new XMLHttpRequest();
            }else{

                xmlhttp = new ActiveXObject("microsodt.XMLHTTP");
            }

        var acct = document.getElementById('acct').value;
        var quicktask = document.getElementById('quicktask').value;
        // var taskstatus = 'Active';
        var user = document.getElementById('user').value;

        xmlhttp.onreadystatechange = function(){

            if (xmlhttp.readyState==4) {
                document.getElementById('panel-body').innerHTML = xmlhttp.responseText;

            }   
        }
            url = "addTask.php?acct="+acct+"&quicktask="+quicktask+"&user="+user;
            xmlhttp.open("GET", url, true);
            xmlhttp.send();

        }

account_functions.php --- PHP函数从mysql获取数据的地方

     public function accountActiveTasks(){
      $varacctname = $_REQUEST['acctname'];
      $varViewActiveTasks = mysql_query("SELECT * from tasks WHERE taskresource='$varacctname' && taskstatus='Active'");

      while ($rows= mysql_fetch_array($varViewActiveTasks)) {
           $this->accttask = $rows['tasktitle'];
           $this->acctTaskStatus = $rows['taskstatus'];
           $this->acctTaskOwner = $rows['taskowner'];

                              echo "<div class=\"timeline-messages\">

                          <div class=\"msg-time-chat\">
                              <a href=\"#\" class=\"message-img\"><img class=\"avatar\" src=\"img/chat-avatar.jpg\" alt=\"\"></a>
                              <div class=\"message-body msg-in\">
                                  <span class=\"arrow\"></span>
                                  <div class=\"text\">
                                      <p class=\"attribution\"><a href=\"#\">$this->acctTaskOwner at 1:55pm, 13th April 2013</a></p>
                                      <p> $this->accttask</p>
                                  </div>
                              </div>
                          </div>
                          <!-- /comment -->
                      </div>";
      }

我的目标是每次tasks.js运行时,AccountView.php中的php代码都会刷新。有点像附加数据。目前数据被推送到 mysql 表,但我必须刷新才能看到它。我希望它在成功时自动显示。

4

2 回答 2

0

试试看

window.location.reload();

于 2013-11-06T06:46:02.443 回答
0

什么是panel-body,它是一个类。在响应中,您正在添加对它的响应,我认为您的意图是让 id="panel-body"

如果您想将响应附加到“面板主体”Div,您可以使用此 jquery 语句

           if (xmlhttp.readyState==4) {
            $('#panel-body').append(xmlhttp.responseText);

        }  
于 2013-11-06T06:32:35.833 回答