简体   繁体   English

在Ajax之后重新加载PHP代码

[英]Reload PHP code after Ajax

i am still learning here folks, so excuse my code if its messy. 我还在这里学习,请谅解我的代码是否混乱。 I have 3 separate pages as follow: 我有3个单独的页面,如下所示:
AccountView.php---Where the data is shown: 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 --> graps one input from AccountView.php task.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 ---Where the PHP function gets the data from mysql 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>";
      }

My goal is that every time the tasks.js runs, the php code in AccountView.php is refreshed. 我的目标是每次task.js运行时,AccountView.php中的php代码都会刷新。 sort of like appending the data. 有点像追加数据。 Currently the data gets pushed to the mysql table but i have to refresh to see it. 目前数据被推送到mysql表,但是我必须刷新才能看到它。 I would like for it to show automatically on success. 我希望它在成功时自动显示。

What is panel-body that is a class.In the response you are adding response to it i think your intention is to have id="panel-body" 什么是面板类,是一类。在响应中,您要添加响应,我想您打算使用id =“ panel-body”

If you want to append the response to the "panel-body" Div you may use this jquery statement 如果要将响应附加到“ panel-body” Div,则可以使用此jquery语句

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

        }  

Try it 试试吧

window.location.reload(); window.location.reload();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM