Load div with ajax

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
Stoker 4.0
Registered User
Posts: 1483
Joined: Sun Feb 13, 2011 1:33 pm
Location: Funen, Denmark
Name: Ulrik Christensen
Contact:

Load div with ajax

Post by Stoker 4.0 » Sat Aug 06, 2016 9:29 am

Im trying to load a div each 5 seconds for an ext of mine.
Did a little googleing and found this:

Code: Select all

<script>
function autoRefresh_div() {
    $("#divajax").load("load.html", function() {
        setTimeout(autoRefresh_div, 5000);
    });
}
</script>
I am certainly missing something because it doesnt work :mrgreen:
Any ideas how to do this?

User avatar
k0nsl
Registered User
Posts: 89
Joined: Mon Mar 25, 2013 11:17 pm
Location: Scandinavia
Name: Eduard Drehner
Contact:

Re: Load div with ajax

Post by k0nsl » Sat Aug 06, 2016 12:49 pm

What you need is setInterval(): :)

[EDIT: I have a working example in the sidebar of my blog, here.]
-k0nsl
Stoker 4.0 wrote:Im trying to load a div each 5 seconds for an ext of mine.
Did a little googleing and found this:

Code: Select all

<script>
function autoRefresh_div() {
    $("#divajax").load("load.html", function() {
        setTimeout(autoRefresh_div, 5000);
    });
}
</script>
I am certainly missing something because it doesnt work :mrgreen:
Any ideas how to do this?
I'm a programmer, server administrator, designer, spokesman and factotum of a wide-variety of web pages.

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3989
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Load div with ajax

Post by kasimi » Sat Aug 06, 2016 1:23 pm

Using setInterval() usually isn't recommended when dealing with AJAX requests as things can get messy when the server takes a long time to respond. It might be what you want your code to do but most of the time it isn't.

I think what's missing here is simply the initial call to the function.

Code: Select all

function autoRefresh_div() {
    $("#divajax").load("load.html", function() {
        setTimeout(autoRefresh_div, 5000);
    });
}
autoRefresh_div(); 

User avatar
Stoker 4.0
Registered User
Posts: 1483
Joined: Sun Feb 13, 2011 1:33 pm
Location: Funen, Denmark
Name: Ulrik Christensen
Contact:

Re: Load div with ajax

Post by Stoker 4.0 » Sat Aug 06, 2016 5:01 pm

For some reason that doesnt work either.
The script is placed in overall footer after html.
Both files is located in the template event folder.

Wonder if i need to do something to the url load.html?

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3989
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Load div with ajax

Post by kasimi » Sat Aug 06, 2016 5:35 pm

It's difficult to help without knowing what doesn't work exactly. Hit Ctrl+Shift+Q (in Firefox) to open the Network log and see what's being sent to and received from the server.

User avatar
k0nsl
Registered User
Posts: 89
Joined: Mon Mar 25, 2013 11:17 pm
Location: Scandinavia
Name: Eduard Drehner
Contact:

Re: Load div with ajax

Post by k0nsl » Sat Aug 06, 2016 11:13 pm

Did you try my example? It works fine for what I use it for.
Best wishes,
-k0nsl
Stoker 4.0 wrote:For some reason that doesnt work either.
The script is placed in overall footer after html.
Both files is located in the template event folder.

Wonder if i need to do something to the url load.html?
I'm a programmer, server administrator, designer, spokesman and factotum of a wide-variety of web pages.

User avatar
Stoker 4.0
Registered User
Posts: 1483
Joined: Sun Feb 13, 2011 1:33 pm
Location: Funen, Denmark
Name: Ulrik Christensen
Contact:

Re: Load div with ajax

Post by Stoker 4.0 » Sun Aug 07, 2016 2:09 pm

Thanks for the help. Still doesnt do what I want.
Im taking a look at Senkys Ajax Base and see if I can figure it out ;)

Post Reply

Return to “Extension Writers Discussion”