I have a simple .ajax function that is triggered on a click event. The function triggers successfully, I'm having a hard time deleting the closest <tr> tag to confirm deletion.
$('.delete_item').click(function () {
if (confirm('Delete this location?')) {
$.ajax({
type: "POST",
url: "/Admin/Location/Delete",
data: "{id: '" + $(this).attr('id') + "' }",
contentType: "application/json; charset=utf-8",
dataType: "text",
success: function (msg) {
if (!msg) {
alert('There was an error deleting the location.');
return;
}
else {
$(this).closest('tr').css('background-color', '#df8f8f').delay(800).fadeOut('slow');
}
},
error: function (msg) {
alert('error in ajax call');
},
});
}
return false;
});
Here is the mark-up
<tr class="class">
<td style="width:300px;">Rosana Square</td>
<td>24 Hours</td>
<td style="width:300px;">8555 Monrovia</td>
<td style="width:300px;">http://www.website.com</td>
<td style="width:50px; text-align:center;"><a href="/Admin/Location/Edit/13"><span class="glyphicon glyphicon-edit"></span></a></td>
<td style="width: 50px; text-align: center;"><a href="#_" id="13" class="delete_item"><span class="glyphicon glyphicon-trash"></span></a></td>
</tr>
Inside of this ajax is this no longer relevant? I'm not getting any errors. Can someone identify my error?