我还在这里学习伙计,所以请原谅我的代码,如果它凌乱。
我有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 - &gt;从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表,但我必须刷新才能看到它。我希望它能在成功时自动显示。
答案 0 :(得分:0)
什么是一个类的面板体。在响应中你正在添加响应我认为你的意图是id =“panel-body”
如果你想将响应附加到“panel-body”Div,你可以使用这个jquery语句
if (xmlhttp.readyState==4) {
$('#panel-body').append(xmlhttp.responseText);
}
答案 1 :(得分:0)
试试吧
window.location.reload();