I have an HT开发者_如何转开发ML Table with each row:
<table>
<tr><td><a href='#' id='1' class='delete'>delete</a></td></tr>
<tr><td><a href='#' id='2' class='delete'>delete</a></td></tr>
<tr><td><a href='#' id='3' class='delete'>delete</a></td></tr>
</table>
I need a jQuery function that gets the id when the click handler is called:
$('.delete').click(function() {
//Get id and set to num
var num = XXXXX //ID
//Invoke ajax request using num
jQuery.ajax({type:'POST',data:{'num': num}, url:'/user/delete',success:function(data,textStatus){deletePicture(num);;},error:function(XMLHttpRequest,textStatus,errorThrown){}});
});
Two questions: 1) How do I get the ID 2) Is the ajax success callback correct?
Your success callback looks fine (provided that deletePicture
is defined elsewhere).
To get the id, you just need this.id
:
var num = this.id;
var num = $(this).attr('id') I believe?
精彩评论