The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

auto refresh div content ...

View previous topic View next topic Go down

In progress auto refresh div content ...

Post by Ahmed.K on Sun May 25, 2014 2:52 pm


I tested this code, but doesn't work correctly ...

Code:
jQuery(document).ready(function() {
var refreshId = setInterval(function()
{
jQuery('.main).load('/ .main');
}, 20000);
jQuery.ajaxSetup({ cache: false });
});

It makes the .main div hidden.
Any ideas?

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: auto refresh div content ...

Post by SSYT on Mon May 26, 2014 4:04 am

Try my code Smile
Code:
jQuery(document).ready(function() {
  var refreshTime = 2000; // Time of reload
  chacke_time = new Date(); // Get the date.
  setTimeout(function(){
  // your function here...
  }, refreshTime);
  console.log(chacke_time+ ' - Reload time is: ' +refreshTime+ ' sec.');
});

or
Code:
$(document).ready(function(){
 setInterval(function(){
  cache_clear();
  console.log(new Date()+' Refresh !! '+'x secound');
}, 10000);
});

function cache_clear(){
 window.location.reload(1);
};
avatar
SSYT
Forumember

Male Posts : 43
Reputation : 2
Language : RO-10, EN-3, FR-1
Location : Romania

http://help.forumgratuit.ro/forum

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on Mon May 26, 2014 5:51 am

Please read my post again. I ask about auto refresh a specific Div, not the all page.

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: auto refresh div content ...

Post by SSYT on Tue May 27, 2014 12:26 am

Code:
$(document).ready(function(){
 var time = 2000;
 setInterval(function(){
  cache_clear();
  console.log(new Date()+' Refresh !! '+'x secound');
}, time);
});

function cache_clear(){
 jQuery('.main).load('/ .main'); // Div of load and reload single div
};
avatar
SSYT
Forumember

Male Posts : 43
Reputation : 2
Language : RO-10, EN-3, FR-1
Location : Romania

http://help.forumgratuit.ro/forum

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on Tue May 27, 2014 3:51 am


Still does not work properly...

I use this code to add the profile link to the Avatar system.

Code:
$(document).ready(function(){$('tr td.tcr').each(function(){$(this).find('.lastpost-avatar img').wrap('<a href="'+$(this).find('span strong a').attr('href')+'">')})});

but, your code removes the link when reload the div.

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: auto refresh div content ...

Post by Wagner' on Fri Jun 06, 2014 11:34 am

Hello,

You have a syntax error on your code...

Try this:
Code:
$(function(){
var m = $('.main'),
refresh = function(){
m.load('/ .main', function(){
console.log('A refresh was performed.');
});
};
window.setInterval(refresh,20000);

});

Best regards, Wagner
avatar
Wagner'
Forumember

Male Posts : 48
Reputation : 6
Language : Portuguese
Location : Brazil

http://www.bestskins.net/forum

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on Sat Jun 07, 2014 11:25 am

Still the same problem. It removes the Avatar profile-link when reload the div.

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: auto refresh div content ...

Post by Wagner' on Sat Jun 07, 2014 1:09 pm

Can you send your forum link?
avatar
Wagner'
Forumember

Male Posts : 48
Reputation : 6
Language : Portuguese
Location : Brazil

http://www.bestskins.net/forum

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on Sat Jun 07, 2014 3:32 pm

Testhere. Take a look on the Avatar link.

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: auto refresh div content ...

Post by Wagner' on Sat Jun 07, 2014 7:17 pm

This is why you just running one function every 10000 milliseconds, you need to update the both functions...

Try this code:
Code:
$(function(){
    var r = function(){
            var m = $('.statused'),
                refresh = function () {
                    m.load(location.href + ' .statused>*', function () {
                        console.log('A refresh was performed.')
                    })
                };
                $('tr td.tcr').each(function () {
                    $(this).find('.lastpost-avatar img').wrap('<a href="' + $(this).find('strong a').attr('href') + '">')
                });
            };
        window.setInterval(r, 3000);
});

Remove these two Javascripts..
Code:
$(document).ready(function () {
    $('tr td.tcr').each(function () {
        $(this).find('.lastpost-avatar img').wrap('<a href="' + $(this).find('strong a').attr('href') + '">')
    })
});

Code:
$(function () {
    var m = $('.statused'),
        refresh = function () {
            m.load(location.href + ' .statused>*', function () {
                console.log('A refresh was performed.')
            })
        };
    window.setInterval(refresh, 10000)
});

avatar
Wagner'
Forumember

Male Posts : 48
Reputation : 6
Language : Portuguese
Location : Brazil

http://www.bestskins.net/forum

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on Sat Jun 07, 2014 9:38 pm

The Avatar link doesn't work now.

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ange Tuteur on Sun Jun 08, 2014 11:19 pm

Hello Ahmed,

First change the pathname in the load function to /forum, just / is equal to your forum homepage. Secondly add a callback function after the page has loaded to reapply the ava links.

Try the below :
Code:
jQuery(document).ready(function() {
 refreshId = setInterval(function() {
 jQuery('.main').load('/forum .main', function() { $('tr td.tcr').each(function(){$(this).find('.lastpost-avatar img').wrap('<a href="'+$(this).find('span strong a').attr('href')+'">')}); });
 }, 20000);
 jQuery.ajaxSetup({ cache: false });
});
avatar
Ange Tuteur
Forumaster

Male Posts : 13072
Reputation : 2743
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on Sun Jun 08, 2014 11:47 pm

Still doesn't work. See.

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ange Tuteur on Sun Jun 08, 2014 11:57 pm

What are you specifically wanting to reload ?
avatar
Ange Tuteur
Forumaster

Male Posts : 13072
Reputation : 2743
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on Mon Jun 09, 2014 12:06 am

This one .statused.

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ange Tuteur on Mon Jun 09, 2014 12:24 am

That will not work correctly as it will replace every category with the first .statused's contents. It would be better to use .main:has(.statused) as that will only select the .main div which contains the forum content.

Code:
jQuery(document).ready(function() {
 refreshId = setInterval(function() {
jQuery('.main:has(.statused)').load('/forum .main:has(.statused)', function() { $('tr td.tcr').each(function(){$(this).find('.lastpost-avatar img').wrap('<a href="'+$(this).find('span strong a').attr('href')+'">')}); });
 }, 20000);
 jQuery.ajaxSetup({ cache: false });
});
avatar
Ange Tuteur
Forumaster

Male Posts : 13072
Reputation : 2743
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on Mon Jun 09, 2014 12:35 am

Well, it works in the main site.

But Can i load two ids with one load?

Like this:jQuery('Div').load('/ #Div1, #Div2'); ?

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ange Tuteur on Mon Jun 09, 2014 12:53 am

Yes, that should work.
avatar
Ange Tuteur
Forumaster

Male Posts : 13072
Reputation : 2743
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on Mon Jun 09, 2014 1:02 am

No, it doesn't ...

for example this code:

Code:
jQuery(document).ready(function() {
var refreshId = setInterval(function()
{
jQuery('.main').load('/forum .main-box, #pun-info');
}, 10000);
jQuery.ajaxSetup({ cache: false });
});

The result.

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ange Tuteur on Mon Jun 09, 2014 1:42 am

Well from what I see, again you're using .main; the element you'll load the content into. Since you didn't specifically tell the browser which .main to add to, it will instead add the content to all elements with class="main".
avatar
Ange Tuteur
Forumaster

Male Posts : 13072
Reputation : 2743
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on Mon Jun 09, 2014 2:45 am

Yes i know. but i want load.main-box and #pun-info. what i use here?
jQuery('????').load('/forum .main-box, #pun-info');

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ange Tuteur on Mon Jun 09, 2014 10:11 am

It depends, where do you wish it to display ?
avatar
Ange Tuteur
Forumaster

Male Posts : 13072
Reputation : 2743
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on Mon Jun 09, 2014 11:50 am

Give me an example. autorefresh.main-box and #pun-info with one load.

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum