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.
OK done.
index.tpl :
All comments
Welcome:
[] Published in:

Attachment:
Modify Delete
<script> </div> <div>function delItem (id) { </div> <div> $.get(delete.php?id=+id,null,function (msg) { </div> <div> if (1==msg) { </div> <div> $(#t+id).remove(); </div> <div> } else { </div> <div> alert(msg); </div> <div> } } </div> <div> </div> <div> }); </div> <div>} </div> <div></script>
delete.php :
require(common.php);
// Query message information
$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;
}
?>

www.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...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template