The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

auto refresh div content ...

4 posters

Go down

In progress auto refresh div content ...

Post by Ahmed.K May 25th 2014, 9: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?
avatar
Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: auto refresh div content ...

Post by SSYT May 26th 2014, 11: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);
};
SSYT
SSYT
Forumember

Male Posts : 77
Reputation : 15
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 May 26th 2014, 12:51 pm

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

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: auto refresh div content ...

Post by SSYT May 27th 2014, 7: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
};
SSYT
SSYT
Forumember

Male Posts : 77
Reputation : 15
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 May 27th 2014, 10: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.
avatar
Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: auto refresh div content ...

Post by Wagner' June 6th 2014, 6:34 pm

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
Wagner'
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 June 7th 2014, 6:25 pm

Still the same problem. It removes the Avatar profile-link when reload the div.
avatar
Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: auto refresh div content ...

Post by Wagner' June 7th 2014, 8:09 pm

Can you send your forum link?
Wagner'
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 June 7th 2014, 10:32 pm

Test here. Take a look on the Avatar link.
avatar
Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

In progress Re: auto refresh div content ...

Post by Wagner' June 8th 2014, 2:17 am

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)
});

Wagner'
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 June 8th 2014, 4:38 am

The Avatar link doesn't work now.
avatar
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 June 9th 2014, 6:19 am

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 });
});
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K June 9th 2014, 6:47 am

Still doesn't work. See.
avatar
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 June 9th 2014, 6:57 am

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

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K June 9th 2014, 7:06 am

This one .statused.
avatar
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 June 9th 2014, 7: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 });
});
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K June 9th 2014, 7: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'); ?
avatar
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 June 9th 2014, 7:53 am

Yes, that should work.
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K June 9th 2014, 8: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.
avatar
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 June 9th 2014, 8: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".
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K June 9th 2014, 9: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');
avatar
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 June 9th 2014, 5:11 pm

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

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K June 9th 2014, 6:50 pm

Give me an example. auto refresh .main-box and #pun-info with one load.
avatar
Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

Back to top

- Similar topics

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