jquery ajax删除_使用jQuery的动画AJAX记录删除

jquery ajax删除

I'm a huge fan of WordPress' method of individual article deletion. You click the delete link, the menu item animates red, and the item disappears. Here's how to achieve that functionality with jQuery JavaScript.

我非常喜欢WordPress删除个别文章的方法。 单击删除链接,菜单项设置为红色,然后消失。 这是使用jQuery JavaScript实现该功能的方法。

PHP-内容和标题 (The PHP - Content & Header)

The following snippet goes at the top of the page:

以下代码段位于页面顶部:


if(isset($_GET['delete'])) {
	$result = mysql_query('DELETE FROM my_table WHERE item_id = '.(int)$_GET['delete'],$link);
}


The following is used to display the records:

以下用于显示记录:


$result = mysql_query('SELECT * FROM my_table ORDER BY title ASC',$link);
while($row = mysql_fetch_assoc($result)) {
	echo '
   
   
Delete ',$row['title'],'
'; }

jQuery JavaScript (The jQuery JavaScript)


$(document).ready(function() {
	$('a.delete').click(function(e) {
		e.preventDefault();
		var parent = $(this).parent();
		$.ajax({
			type: 'get',
			url: 'jquery-record-delete.php',
			data: 'ajax=1&delete=' + parent.attr('id').replace('record-',''),
			beforeSend: function() {
				parent.animate({'backgroundColor':'#fb6c6c'},300);
			},
			success: function() {
				parent.slideUp(300,function() {
					parent.remove();
				});
			}
		});
	});
});


For every link, we add a click event that triggers the AJAX request. During the request, we transition the containing element to a red background. When the AJAX request returns a "success" response, we slide the element off of the screen.

对于每个链接,我们添加一个点击事件来触发AJAX请求。 在请求期间,我们将包含元素转换为红色背景。 当AJAX请求返回“成功”响应时,我们将元素滑出屏幕。

How would you use this? Share!

您将如何使用它? 分享!

翻译自: https://davidwalsh.name/animated-ajax-jquery

jquery ajax删除

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值