编辑文章AJAX,PHP,javascript [英] edit posts AJAX, PHP, javascript
本文介绍了编辑文章AJAX,PHP,javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个论坛,用户可以在其中编辑其帖子.我不知道该怎么做,但是我尝试了如下操作:
I am creating a forum in which the users can edit their posts. I have no idea how to do that, but i tried something as follows:
php代码显示帖子
while($row = $result->fetch_assoc()) {
echo "<div class='postclass'>";
echo "<span id='postspan".$row['id']."' name='postspan".$row['id']."' >";
echo "<span id='editspan".$row['id']."' name='editspan".$row['id']."' >";
echo "</br>";
echo "Posted By:          <span class='bold'> ".$row['user']."</span>";
if($username==$row['user']){
echo "         ";
echo "<a href='javascript:void(0);' onclick='deletepost(".$row['id'].")' >DELETE </a>   ";
echo "<a href='javascript:void(0)' onclick='editpost(".$row['id'].",'".$row['subject']."','".$row['post']."')' >EDIT </a></br>";
}else{
echo "</br>";
}
点击编辑链接时调用的
javascript函数
javascript function which is called when edit link is clicked
function editpost(postid,subject,post){
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("editspan"+postid).innerHTML=xmlhttp.responseText;
}
};
xmlhttp.open("GET","editpost.php?pid="+postid+"&subject="+subject+"&post="+post,true);
xmlhttp.send();
}
editpost.php页面
$pid=$_GET['pid'];
$subject=$_GET['subject'];
$post=$_GET['post'];
}else{
$pid="";
$subject="";
$post="";
}
echo "<form method='POST' action='globalwall.php'>
<p>Subject:
<label for='subject'></label>
<input type='text' name='subject' id='subject' value='".$subject."' />
</br>
</p>
<p>Post: <br />
<label for='post'></label>
<textarea name='post' id='post' cols='45' rows='5' value='".$post."'></textarea>
</p>
<p>
<input type='submit' name='postbutton' id='postbutton' value='Edit' />
</p>
</form>";
当我单击编辑"按钮时,没有任何反应.即使我在javascript函数中放置了警报消息,它也不会弹出.有人可以帮忙吗?
when i click the edit button nothing is happening. Even if i place an alert message in javascript function, it is also not popping up. Can anyone help please?
推荐答案
替换您的
echo "<a href='javascript:void(0)' onclick='editpost(".$row['id'].",".$row['subject'].",".$row['post'].")' >EDIT </a></br>";
echo "<a href='javascript:void(0)' onclick='editpost(".$row['id'].",\"".$row['subject']."\",\"".$row['post']."\")' >EDIT </a></br>";
这篇关于编辑文章AJAX,PHP,javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文