开发者

jquery keep content in div until ajax content arrives

开发者 https://www.devze.com 2023-03-22 04:20 出处:网络
So I have a Div tag in which I load AJAX content. I want to make it so when a user triggers the AJAX event that it keep开发者_如何学Cs the current content in there with a spinning loading circle in th

So I have a Div tag in which I load AJAX content. I want to make it so when a user triggers the AJAX event that it keep开发者_如何学Cs the current content in there with a spinning loading circle in the center. I am currently using the following code

    j("#AJAXContent")
        .html("reloading")
        .load(Url, "foo="+bar);

However, That code will just replace the current div tag with "reloading" as the text then the new content comes and replaces that.


If you want to show a loading image in the content div then add a class when the ajax call is made. This class will basically show a loading image as a background of the container. The other alternative is have a absolute positioned div which some height/width and loading image in the center. Show this div at the center and top of the container when you make a ajax call.

.loading
{
  background:none url("loading.png") no-repeat center center;
}

j("#AJAXContent").addClass("loading").load(Url, "foo="+bar, function(){
   j("#AJAXContent").removeClass("loading");
});

The other way is to show a loading div on top of content div before you make a ajax call.


Try

j("#AJAXContent").load(Url, "foo="+bar);

j("#AJAXContent").html("reloading") will update the div contents with the message reloading.


This may help: http://jsfiddle.net/SQHgu/, although cross domain request are not allowed (for example only).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号