Last active
August 29, 2015 14:26
-
-
Save tuckbloor/5fb1f7fa6804ad4c2933 to your computer and use it in GitHub Desktop.
javascript check if file exists in a loop of table rows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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