I am using following code to show a spinning wheel:
$("#loading")
.hide()
.ajaxStart(function(){
$(this).show();
setTimeout("3000");
})
.ajaxStop(function(){
$(this).hide("slow");
})
;
and:
<div id="loading">
<img src="loading.gif" alt="Loading" />
</div>
Problem: "setTimeout() is not working. And how can I display the image at the centre of webpage?"
I dont understand why you're using the timer, you can simply turn it on at start of ajax request, and then on success or error turn it off, like:
To have your loading image in the middle of the page, make sure that it's container is within a 100% height parent, and if it is nested, make sure none of its parents are
position:relative
.You use the SetTimeout function in a wrong way
JS
setTimeout
takes 2 paramter, the first one is thecallback
function and the second is thetimeout
in msec eg.or
to display your image in center of the webpage you can use eg. this technique