I have an Ajax Call, in an OnClick event.
Inside the OnClick, I set a var type = $(this).closest("table").attr("id");
I am trying to call this type inside the Ajax's complete function().
But it shows as undefined.
Maybe someone can explain a lil bit why this is happening?
Thanks!!
$(document).on('click','.swaction',function(event){
var pdfId = $(this).closest('tr').find('td:first').html();
var type = $(this).closest("table").attr("id");
event.preventDefault();
if( $(this).data('action') === 'delete' )
{
var currentElement = this;
if( confirm( "¿Está seguro de querer eliminar el \nPDF Nº " + pdfId + '?' ) )
{
$.ajax({
url: 'ct_form_procesar_escaneos/pdf/delete/'+ type + '/' + pdfId,
method: 'POST',
error: function( jqXHR, textStatus, errorThrown )
{
alert( errorThrown );
},
complete: function()
{
var a = type; // undefined
$(currentElement).closest('tr').fadeOut(600, function(){
$(currentElement).remove();
$.procesar_escaneos.removeOnEmpty( type );
});
}
});
}
}
type