/    Sign up×
Community /Pin to ProfileBookmark

Loadericon not being displayed after function has been called before

I have this function to load pages:

`function LoadPage(page) {
var delay = 500;
$(“#loaderIcon”).show();
jQuery.ajax({
url: page,
success:function(data){
setTimeout(function() {
$(“#main-content”).show();
$(“#main-content”).html(data);
$(“#loaderIcon”).hide();
}, delay);
},
error:function (){}
});
}`

When the page is being loaded for the first time, this code gets executed:
`LoadPage(‘dashboard.php’);`

Now when I click on the dashboard button in the menu, it does exactly this again;
`<a href=”#” class=”nav-link active” onclick=”LoadPage(‘dashboard.php’)”>`

However, it only shows the loader the first time the function is getting executed.
It seems as if the settimeout interval does not work the second time, immediately loading the page instead of showing a loader icon for 500 ms.

How can I solve this?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumSep 12.2020 — Where is #loaderIcon located, inside #main-content?
Copy linkTweet thisAlerts:
@uwrpauthorSep 12.2020 — Thank you for the quick reply.

It's actually above the main-content span.

&lt;div id="loaderIcon" style="display: flex; justify-content: center;"&gt;<br/>
&lt;img src="dist/img/loader.gif"&gt;<br/>
&lt;/div&gt;<br/>
&lt;span id="main-content"&gt;&lt;/span&gt;
Copy linkTweet thisAlerts:
@SempervivumSep 12.2020 — I created a test page with the code you posted and it works fine. Maybe the error is located somewhere else. If that site is online, please post the URL.
Copy linkTweet thisAlerts:
@uwrpauthorSep 12.2020 — Inside the page dashboard.php, there was also a loader div. After removing that one it worked fine.

Thank you very much for the help.
×

Success!

Help @uwrp spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...