I want to remove a table’s row with jquery. When i write this jQuery(this).parent().parent().fadeOut(); statement outside ajax success function it fades out row. but it does not work if written within ajax success function.
jQuery(document).ready(function() {
jQuery('.assignme').click(function(){
id = jQuery(this).attr('rel');
jQuery.ajax({
url:'home.php?ajax=1&action=assing_to_agent&application_id='+id,
success:function(data){
if(data==-1)
alert('Assigned to someone else');
jQuery(this).parent().parent().fadeOut();
}
});
return false;
});
});
Here is html
<tr>
<td><button class="assignme" rel="<?php echo $row_rs_report['application_id']; ?>">Assign Me</button></td></tr>
Also if someone can tell me about a good practice to send a value to ajax method as i m sending id using rel attribute?
When your success is called the this statement is the window (as far as i remember). At least, it is probably not the element you were trying to refer to.
[EDIT] Actually, you could event use the id attribute instead of rel, thus, you could point to that button (as far as the id is unique) and delete its td parent.
HTML could become:
And js:
Declaring a var to pass arguments to the ajax is the way i use to do, maybe there is a better one.
Btw, the var statement can guarantee the local use of the var (safer and quicker)
Max