Deleting data without refreshing - PHP_PHP Tutorial
WBOY
Release: 2016-07-13 17:34:50
Original
980 people have browsed it
First of all, this example is modified based on the edited version of the guestbook.
We used jquery.js to implement ajax and dom deletion
First add
Add an id="t"
to the table
Write a js:
<script></div>
<div>function delItem (id) {</div>
<div>$.get(delete.php?id=+id,null,function (msg) {//ajax request, execute the following code after the request</div>
<div>if (1==msg) {//Return 1 to indicate success</div>
<div>$(#t+id).remove();//Delete the table with id txx</div>
<div>} else {//Otherwise an error message will pop up</div>
<div>alert(msg);</div>
<div>}</div>
<div> </div>
<div>});</div>
<div>}</div>
<div></script>
Delete the link and change it to href="javascript:delItem()"
The modification to delete.php is to change the error statement to output directly.
$q = $query->query(select * from gb_content where id=.intval($_GET[id]));
$rs = $query->fetch_array($q);
$error = array();
if ($rs[user_id]!=intval($_SESSION[user_id])) {// Determine whether user_id is the same
$error = You cannot delete this information, you can only delete what you posted;
}
if (!$error) {
$query->query(delete from gb_content where id=.intval($_GET[id]));//Delete statement
if ($rs[user_file]) {//Delete attachment
@unlink(uploads/.$rs[user_file]);
}
echo 1;//Indicates success
} else {
echo $error;
}
?>
http://www.bkjia.com/PHPjc/508432.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508432.htmlTechArticleFirst of all, this example is modified based on the edited version of the guestbook. We used jquery.js to implement ajax and dom deletion. First, add script type=text/javascript src=lib/jquery.js/script and add an id=t to the table...
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn