Home  >  Article  >  Backend Development  >  PHP教程:利用jquery实现无刷新删除数据_PHP

PHP教程:利用jquery实现无刷新删除数据_PHP

WBOY
WBOYOriginal
2016-06-01 12:20:501076browse

jQuery

首先本例基于留言本整理版修改。

我们使用了jquery.js来实现ajax和dom删除,首先加入:

给table加个

id="t"

写个js:

<script> <br />function delItem (id) { <br />$.get('delete.php?id='+id,null,function (msg) {//ajax请求,请求后执行下面代码 <br />if ('1'==msg) {//返回1表示成功 <br />$('#t'+id).remove();//把id为txx 的表格删除 <br />} else {//否则弹出错误信息 <br />alert(msg); <br />} <br /><br />}); <br />} <br /></script>

删除链接改成

href="javascript:delItem('')"

delete.php的修改就是把错误语句改成直接输出就行了。

OK完成。

Statement:
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