0

i am still learning here folks, so excuse my code if its messy. I have 3 separate pages as follow:
AccountView.php---Where the data is shown:

                      <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

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

     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. sort of like appending the data. Currently the data gets pushed to the mysql table but i have to refresh to see it. I would like for it to show automatically on success.

5
  • Refer this stackoverflow.com/questions/15697755/… Commented Nov 6, 2013 at 6:30
  • 1
    what is the point of using ajax when you reload your page anyway? Commented Nov 6, 2013 at 6:36
  • i don't want to reload the page, i just want to append the data. i will post an image to show you what i mean.. Commented Nov 6, 2013 at 6:41
  • sorry can't post image due to reputation. its similar to a chat window. Commented Nov 6, 2013 at 6:52
  • I think you have seen my answer Commented Nov 6, 2013 at 7:33

2 Answers 2

0

Try it

window.location.reload();

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, i tried it but i still don't want all the page to be reloaded. otherwise there is not point of Ajax i am assuming.
0

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"

If you want to append the response to the "panel-body" Div you may use this jquery statement

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

        }  

2 Comments

Thanks Pavan, but this didn't work. i created opentasks id surrounding the PHP code in Accountsview.php but still couldn't accomplish it.
You can do one thing in ajax call after updation of data try to get the new data what you want to have, as response and write that into your Div

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.