JQUERY How do I fadeout on post success?
I want to fade out开发者_如何学运维 my div once the button inside it is clicked, and the resulting post request returns successful.
$('.btn').click(function(){
var u_id = $(this).attr('id');
$.post("actdeact.php",{do_action:'activate',uid:u_id},function(data){
$(this).fadeOut("500");
alert('loaded '+data);
});
});
since the divs are dynamically generated I used a class instead of an id (or each()). But it seems I cannot use $this for the fadeout.....any ideas?
Try this:
$('.btn').click(function(){
var that=$(this);
var u_id = $(this).attr('id');
$.post("actdeact.php",{do_action:'activate',uid:u_id},function(data){
that.fadeOut("500");
alert('loaded '+data);
});
});
The idea is to get the reference to $(this) before calling $.post
精彩评论