MyBB Community Forums

Full Version: Refresh every 5 second
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.
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.
Just testet and works from my page.
I'm not really sure of the relevance of your code changes to the original question to be honest.
Sry my bad, have misunderstood it completely.
@MrBrechreiz, so that actually works?
The refresh is already working, only there is not what you are looking for. Sorry.