I'm polling the status of a background process. I'm trying to use the HTML5 data attribute to pass the :status(model attribute) of the background process to the js polling function. The status successfully updates when the background job is finished, but my javascript is not retrieving the updated status.
<div class="report" data-report-id="<%= @report.id %>" data-report-completed="<%= @report.completed? %>">
<% if @report.completed? %>
I'm certain that the @report.completed? method works correctly. Here is my javascript. Accessing the data-report-completed attribute is not returning the updated status.
$(document).ready(function() {
if ($(".report-loading").length > 0) {
showActivityIndicator();
console.log("Loading...");
setTimeout(checkReportStatus, 3000);
}
});
function checkReportStatus() {
var report_completed = $(".report").attr("data-report-completed");
if (report_completed == true) {
console.log("Completed");
var report_id = $(".report").attr("data-report-id");
location.reload();
}
else {
console.log("In progress...");
setTimeout(checkReportStatus, 3000);
}
}
data()instead ofattr()?data()and still no luck.