MyBB Community Forums
Refresh every 5 second - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: 1.8 Support (https://community.mybb.com/forum-175.html)
+--- Forum: General Support (https://community.mybb.com/forum-176.html)
+--- Thread: Refresh every 5 second (/thread-196684.html)



Refresh every 5 second - Sazze - 2016-07-30

Hi,
I just noticed that my mebers is always refreshing 5 seconds (which makes them online and eventually generate lots of time spent online, which I don't wanna).

Video: https://u.pomf.is/ypteyo.mp4

NOTE: I told the user to stay on the index page without refreshing.

Can this script be causing this?

<script type="text/javascript">
 jQuery(document).ready(function(){
var interval = 5000;
var refresh = function() {
// Ajax Request 
jQuery.ajax({
url: "usercp.php?action=notification_ajax",
data: {
key: '{$mybb->post_code}'
},
type: "POST",
dataType: "html",
success: function (data) {
$('#notificationcounter').html(data);
setTimeout(function() {
refresh();
}, interval);
},
error: function (xhr, status) {
setTimeout(function() {
refresh();
}, interval);
},
complete: function (xhr, status) {
}
});
};
refresh();
});
</script>

Thanks.  Smile


RE: Refresh every 5 second - MrBrechreiz - 2016-07-30

Open member_profile template and search for

{$online_status}

replace to

<span id="online_status">{$online_status}</span>

search for

{$timeonline}

replace to

<span id="timeonline">{$timeonline}</span>

add after

</table>

this

<script type="text/javascript">
var interval = 5000;
$(document).ready(function() {
 	 $("#online_status").fadeOut("fast").load(" #online_status").fadeIn("fast");
	$("#timeonline").fadeOut("fast").load(" #timeonline").fadeIn("fast");
   var refreshId = setInterval(function() {
      $("#online_status").fadeOut("fast").load(' #online_status').fadeIn("fast");
	   $("#timeonline").fadeOut("fast").load(' #timeonline').fadeIn("fast");
   }, interval);
   $.ajaxSetup({ cache: false });
});
</script>

Hope this helps Rolleyes

Addition:
The Time Spent Online time is updated only when the user clicks something in forum.


RE: Refresh every 5 second - Matt - 2016-07-30

That script probably would do it yeah as it's checking notifications every 5 seconds; that would count as activity so would update the last activity date in the user's session.


RE: Refresh every 5 second - MrBrechreiz - 2016-07-30

Just testet and works from my page.


RE: Refresh every 5 second - Matt - 2016-07-30

I'm not really sure of the relevance of your code changes to the original question to be honest.


RE: Refresh every 5 second - MrBrechreiz - 2016-07-30

Sry my bad, have misunderstood it completely.


RE: Refresh every 5 second - Sazze - 2016-07-30

@MrBrechreiz, so that actually works?


RE: Refresh every 5 second - MrBrechreiz - 2016-07-30

The refresh is already working, only there is not what you are looking for. Sorry.