<style type="text/css">@import url("cstyle.css");</style>
<style type="text/css">@import url("style.css");</style>
<script type="text/javascript">
function deleteComment(id)
{
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","deleteComment.php?id="+id,true);
xmlhttp.send();
}
$(document).ready(function()
{
deleteComment(id);
});
</script>
<?php
include_once("pass.php");
include("common.php");
class ComA
{
static function reportComment()
{
$query = mysql_query("SELECT * FROM comments WHERE Flag =1");
$number=mysql_num_rows($query);
// number of rows to show per page
$rowsperpage = 15;
// find out total pages
$totalpages = ceil($number/$rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage']))
{
// cast var as int
$currentpage = (int) $_GET['currentpage'];
}
else
{
// default page num
$currentpage = 1;
}
//if current page is greater than total pages...
if ($currentpage > $totalpages)
{
// set current page to last page
$currentpage = $totalpages;
}
//if current page is less than first page...
if ($currentpage < 1)
{
// set current page to first page
$currentpage = 1;
}
//the offset of the list, based on current page
$offset = ($currentpage - 1) * $rowsperpage;
// get the info from the db
// while there are rows to be fetched...
$sql = mysql_query("SELECT * FROM comments WHERE Flag = 1 ORDER BY id DESC LIMIT $offset, $rowsperpage");
?>
<div id="count">
<div id="title"><b>Edit Reported Comments</b></div>
<?php
if($number==1)
echo $number . " COMMENT";
else
echo $number . " COMMENTS";
?>
</div>
<?php
while ($content = mysql_fetch_assoc($sql))
{
?>
<div id="delete">
<?php $javaid=$content['id']; ?>
<a href="<?php $_GET['location'] ?>" onClick="deleteComment(<?php echo $javaid ?>)" ><img src="_" onmouseover="_" onmouseout="_"></a>
</div>
<div id="comment">
<?php
echo $content['username'] . " <br/> " ;
?>
<div id="timestamp">
<?php
echo "Posted " . $content['date'];
?>
</div>
<?php
echo $content['comment'];
?>
</div>
<div class="greyRule"><hr /></div>
<?php
} // end while
/****** build the pagination links ******/
// range of num links to show
$range = 3;
?>
<div id="page">
<?php
// if not on page 1, don't show back links
if ($currentpage > 1)
{
?>
<a href="<?php echo $_GET['location'] ?>¤tpage=1" class="blue"><< first </a>
<?php
// get previous page num
$prevpage = $currentpage - 1;
?>
<a href="<?php echo $_GET['location'] ?>¤tpage=<?php echo $prevpage ?>" class="blue">< previous </a>
<?php
}
// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++)
{
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages))
{
// if we're on current page...
if ($x == $currentpage)
{
// 'highlight' it but don't make a link
echo " <b>$x</b> "; //needs to be RIGHT ALIGNED
// if not current page...
}
else
{
// make it a link
?>
<a href="<?php echo $_GET['location'] ?>¤tpage=<?php echo $x ?>" class="blue"> <?php echo $x?></a>
<?php
} // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($currentpage != $totalpages && $totalpages!=0)
{
// get next page
$nextpage = $currentpage + 1;
?>
<a href="<?php echo $_GET['location'] ?>¤tpage=<?php echo $nextpage ?>" class="blue"> next ></a>
<a href="<?php echo $_GET['location'] ?>¤tpage=<?php echo $totalpages ?>" class="blue"> last >></a>
<?php
}
?>
</div>
<?php
}
}
ComA::reportComment();
?>
回答
您正在以错误的方式使用XmlHttpRequest。更好的办法是使用这样的事情 - http://api.jquery.com/category/ajax/ 此外,您在页面加载调用deleteComment(),而不是点击链接
这是被称为..... <?php include(“pass.php”)的函数。 级别删除 { \t静态函数deleteComment($ comId) \t { \t \t $ deleteComment =请求mysql_query( “DELETE FROM评论WHERE ID = '” $ comId。 “'”)或死亡(mysql_error); \t} } Delete :: deleteComment($ _ GET ['id']); ?> –
如果您正在使用jQuery,这是很简单的:
更改删除按钮对这样的事情:
<a class="delete_btn" rel="<?php echo $comment_id; ?>" href="#"><img src="_" onmouseover="_" onmouseout="_"></a>
,并把这个脚本的地方在它下面:
<script>
$('.delete_btn').click(function() {
var id = $(this).attr('rel');
$.get('deleteComment.php', {'id' : id}, function(data) {
$('#div_with_the_deleted_comment').html('This comment was deleted.');
return false;
}
});
</script>
我试过这个,它没有工作。我添加了导入语句。我需要做其他事吗? –
nvm我用一个更简单的解决方案解决了这个问题。我使用链接href直接调用该函数,然后重定向回该页面。感谢您的所有帮助。 –
@Gavin Sellers很高兴能听到;)不客气! – Quasdunk
- 1. Javascript函数没有被调用onclick?
- 2. Javascript函数没有在按钮的onclick事件中被调用
- 3. Javascript:为什么我的函数没有被onclick调用?
- 4. 在javascript中调用所有onclick事件中的函数
- 5. 我想在调用另一个函数时调用函数
- 6. 我的keyPressed函数没有被调用
- 7. 我的JavaScript文件中的jquery函数没有被调用
- 8. 从onclick事件调用jQuery函数
- 9. 将数据推送到JavaScript函数使用onClick事件调用
- 10. 函数不被调用使用onClick事件调用的主JS函数
- 11. OnClick事件调用一个js函数和一个回调函数
- 12. JavaScript函数不会被调用所有
- 13. Javascript函数未被onclick调用
- 14. AJAX函数没有被调用与按钮onclick函数
- 15. 函数没有被调用
- 16. 函数没有被调用
- 17. 该按钮没有调用javascript函数
- 18. SetInterval没有调用该函数 - javascript
- 19. JavaScript函数没有被调用正确
- 20. 我如何在onClick函数中编写JavaScript代码以及我也想调用另一个函数
- 21. 如何替换的onclick函数调用我的函数调用
- 22. ASP.NET调用JavaScript函数OnClick
- 23. Javascript innerHTML调用onclick函数
- 24. 条件满足但函数没有被调用(基本的JavaScript)
- 25. 我想在表中调用一个JavaScript函数td php
- 26. Javascript addEventListener函数被调用而没有触发事件
- 27. JS事件。只有一个事件处理函数被调用?
- 28. 使用onclick调用函数,并在该函数内调用另一个函数使用onclick
- 29. 的JavaScript的onclick没有一个函数调用
- 30. 如何在onclick事件中调用多个JavaScript函数?
这个JavaScript作为卡莱d by onClick是一个ajax请求,php函数reportComment本身被另一个文件中的ajax调用。 –