auto refresh div content ...

Go down

In progress auto refresh div content ...

Post by Ahmed.K on 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?

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 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);
};
avatar
SSYT
Forumember

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

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 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
};
avatar
SSYT
Forumember

Male Posts : 71
Reputation : 12
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 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.

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

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 June 7th 2014, 8: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 June 7th 2014, 10:32 pm

Test here. 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 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)
});

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

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

Male Posts : 13201
Reputation : 2917
Language : EN10, FR5, JA5
Location : Macungie, PA

https://github.com/SethClydesdale

Back to top Go down

In progress Re: auto refresh div content ...

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

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 June 9th 2014, 6:57 am

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

Male Posts : 13201
Reputation : 2917
Language : EN10, FR5, JA5
Location : Macungie, PA

https://github.com/SethClydesdale

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on June 9th 2014, 7: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 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 });
});
avatar
Ange Tuteur
Forumaster

Male Posts : 13201
Reputation : 2917
Language : EN10, FR5, JA5
Location : Macungie, PA

https://github.com/SethClydesdale

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on 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'); ?

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 June 9th 2014, 7:53 am

Yes, that should work.
avatar
Ange Tuteur
Forumaster

Male Posts : 13201
Reputation : 2917
Language : EN10, FR5, JA5
Location : Macungie, PA

https://github.com/SethClydesdale

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on 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.

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 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".
avatar
Ange Tuteur
Forumaster

Male Posts : 13201
Reputation : 2917
Language : EN10, FR5, JA5
Location : Macungie, PA

https://github.com/SethClydesdale

Back to top Go down

In progress Re: auto refresh div content ...

Post by Ahmed.K on 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');

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 June 9th 2014, 5:11 pm

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

Male Posts : 13201
Reputation : 2917
Language : EN10, FR5, JA5
Location : Macungie, PA

https://github.com/SethClydesdale

Back to top Go down

In progress Re: auto refresh div content ...

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

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

Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

Back to top


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