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 25/5/2014, 21:52


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 26/5/2014, 11:04

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 : 44
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 26/5/2014, 12:51

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 27/5/2014, 07:26

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 : 44
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 27/5/2014, 10:51


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 6/6/2014, 18:34

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 7/6/2014, 18:25

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 7/6/2014, 20:09

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 7/6/2014, 22:32

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 8/6/2014, 02:17

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 8/6/2014, 04:38

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 9/6/2014, 06:19

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 : 13175
Reputation : 2876
Language : EN10, FR5
Location : Macungie, PA

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on 9/6/2014, 06:47

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 9/6/2014, 06:57

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

Male Posts : 13175
Reputation : 2876
Language : EN10, FR5
Location : Macungie, PA

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on 9/6/2014, 07:06

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 9/6/2014, 07:24

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 : 13175
Reputation : 2876
Language : EN10, FR5
Location : Macungie, PA

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on 9/6/2014, 07:35

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 9/6/2014, 07:53

Yes, that should work.
avatar
Ange Tuteur
Forumaster

Male Posts : 13175
Reputation : 2876
Language : EN10, FR5
Location : Macungie, PA

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on 9/6/2014, 08:02

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 9/6/2014, 08:42

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 : 13175
Reputation : 2876
Language : EN10, FR5
Location : Macungie, PA

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on 9/6/2014, 09:45

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 9/6/2014, 17:11

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

Male Posts : 13175
Reputation : 2876
Language : EN10, FR5
Location : Macungie, PA

http://fmdesign.forumotion.com

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on 9/6/2014, 18:50

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