'How to show Progress bar while loading page in div using Jquery
I am loading another page in one div using jQuery.Load("#divid","pageURL");
I have anchor tag on that anchor tag click I am calling jQuery.load("#divid","pageURL"); function this function takes time to load page in that div, so I want to show loading image and changing the cursor style.
Below is the code snippet which I am using currently. in script.js file I have written function like that
function loadReview(el) {
jQuery("#productName1").load(el);
return false;
}
and I have anchor tag inside .aspx page like that.
<a onclick='loadReview(\"" + strexternalURL + "\");' href='#productName1'></a>
Solution 1:[1]
jQuery( "#productName1" ).load(el, function() {
//loaded
jQuery("#productName1").addClass("loaded");
});
with in your css something like this:
#productName1 {
background-image: url('images/loading.gif');
background-position: center center;
}
#productName1.loaded {
background-image: none;
}
Solution 2:[2]
add a script to simulate loading before the call and when the call is finished, remove.
example:
function loadReview(el) {
// add a gif loading in a div loader
jQuery("div.loadingDiv").html('<img src="link gif loading" />');
jQuery("div.loadingDiv").show();
jQuery("#productName1").load(el, function() {
jQuery("div.loadingDiv").hide();
});
return false;
}
html:
<div class="loadingDiv" style="display:none"></div>
<a onclick='loadReview(\"" + strexternalURL + "\");' href='#productName1'></a>
Solution 3:[3]
Use success method
function loadReview(el) {
$("div.loaderDiv").html('<img src="imglink" />');
$("div.loaderDiv").show();
$("#productName1").load(el);
return false;
success: $("div.loaderDiv").hide();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | bondythegreat |
| Solution 2 | Antonio Jr |
| Solution 3 | Sridhar R |
