Every 10 seconds, it calls this ajax to reload the number of received mails.
Sometime, I open my application at over 5 tabs at once.
Obviously each tab try to call this ajax so my PC gets so heated :(
I want to run this ajax only in the tab which is in active. So rest of 4 tabs shouldn't call the ajax unless the tab is active.
How can I implement that condition to this?
refresh_mail_count.js
jQuery(document).ready(function () {
refreshMail();
});
function refreshMail() {
$.ajax({
url: "/messages/refresh_mail",
type: "GET",
dataType: "script",
});
}
refresh_mail.js.erb
$('#message_count').html("<%= j(render(:partial => 'layouts/message_received_count', :object => @message_count)) %>");
setTimeout(refreshMail,10000);