Skip to content

Instantly share code, notes, and snippets.

@tuckbloor
Last active August 29, 2015 14:26
Show Gist options
  • Save tuckbloor/5fb1f7fa6804ad4c2933 to your computer and use it in GitHub Desktop.
Save tuckbloor/5fb1f7fa6804ad4c2933 to your computer and use it in GitHub Desktop.
javascript check if file exists in a loop of table rows
$(selector).on('click', '#id or .class name', function() {
var id = $(this).closest('tr').find('#id').val();
//post the id to a url to update
$.post('/url', {
id: id
});
});
setInterval(function () { update() }, 10000);
function update() {
$('.loader').each(function () {
var id = $(this).closest('tr').find('#id').val();
var response = $.ajax({
url: '/tmp/file_name_' + id + '.pdf',
type: 'HEAD',
async: false
}).status;
if (response == 404) {
$(this).html("<i class='btn btn-primary fa fa-refresh print'>");
} else {
$(this).html("<i class='btn btn-danger fa fa-print'></i>")
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment