$.ajax 的 jQuery 加载状态
我使用以下代码从数据库获取数据(从 cs 页面本身创建 html 代码)并将 html 代码绑定到 div。
问题:
如果数据库大小较大,则需要一些时间才能显示结果。我想在那个位置放置一个loading.gif 图像。一旦获得数据,我就必须隐藏加载图像。
编辑:
问题:一旦隐藏,show() 就不起作用。
<div id="searchContainer" class="search_outer">
<div id="Loading"></div></div>
代码:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
data: "{ searchText: '" + searchText + "', product: '" + product + "', category: '" + category + "', artist:'" + artist + "'}",
url: "Search.aspx/FetchSearchResult",
dataType: "json",
success: function(data) { $("#Loading").hide(); $("#searchContainer").html(data.d[0]);}});
$("#ajax-query-place").ajaxStart(function() {
$("#Loading").show();
});
Geetha。
I am using the following code to get data from the database( from cs page itself i am creating the html code) and binding the html code to the div.
Problem:
If the database size is higher it takes some time to show the result. thet time i want to shoe a loading.gif image in that location. Once it get the data i have to hide the load image.
Edit:
Problem: Once it get hide, then the show() is not working.
<div id="searchContainer" class="search_outer">
<div id="Loading"></div></div>
Code:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
data: "{ searchText: '" + searchText + "', product: '" + product + "', category: '" + category + "', artist:'" + artist + "'}",
url: "Search.aspx/FetchSearchResult",
dataType: "json",
success: function(data) { $("#Loading").hide(); $("#searchContainer").html(data.d[0]);}});
$("#ajax-query-place").ajaxStart(function() {
$("#Loading").show();
});
Geetha.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题在于您的
success:
回调。当您这样做时:您将覆盖
#Loading
元素,因为它位于#searchContainer
内部。请改用
append()
。或者只需将
#Loading
元素移到#searchContainer
元素之外。编辑:
我猜您没有名为
#ajax-query-place
的元素。你应该使用:
The trouble is in your
success:
callback. When you do:You are overwriting the
#Loading
element because it is inside#searchContainer
.Use
append()
instead.Or just move the
#Loading
element outside of the#searchContainer
element.EDIT:
I'm guessing you don't have an element called
#ajax-query-place
.You should use:
简单:在启动 ajax() 方法之前,显示旋转图像。在success方法中,再次隐藏。
Easy: Before launching the ajax()-methode, display the spinner image. In the success method, hide it again.
$("#ajax-query-place") 是获取或发送 ajax 查询的元素。
$("#ajax-query-place") is an element which is getting or sending ajax queries.