[英]Delete using ajax
I have a div in which its data is populated from the backend php. 我有一个div,其中的数据是从后端php填充的。 I am using codeigniter here.
我在这里使用codeigniter。 The div is something like this
div是这样的
if(isset($result))
{
echo '
<div>
<div>
$result->value
</div>
<a>Delete</a>
</div>
';
}
The delete is done using ajax. 删除是使用ajax完成的。 But how do I do a refresh of the div which is not supposed to show anything after the deletion?
但是,如何删除删除后不显示任何内容的div?
Do this in your ajax success function
: 在
ajax success function
:
$(this).closest('div').slideUp().remove();
This way visually you would see a slideup and after sliding up this would get removed from the dom and this won't appear again if successfully removed from db. 这样,您将在视觉上看到一个向上滑动,向上滑动后将被从dom中删除,并且如果成功从db中删除,则不会再次出现。
Then if you refresh your page you won't see that div again.
having some kind of class identifier on delete is always a good way for future extensions/modifications. 在删除时具有某种类标识符始终是将来扩展/修改的好方法。
<div>
<div>
$result->value
</div>
<a class="deleteme">Delete</a>
</div>
either case you can use this: 无论哪种情况,您都可以使用以下方法:
$(document).on('click', '.deleteme', function() {
//your delete stuff
if (your delete was successful) {
$(this).parent().fadeOut(500);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.