$.ajax 的 jQuery 加载状态

发布于 2024-09-01 23:40:33 字数 981 浏览 10 评论 0原文

我使用以下代码从数据库获取数据(从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

手心的海 2024-09-08 23:40:33

问题在于您的 success: 回调。当您这样做时:

$("#searchContainer").html(data.d[0]);

您将覆盖 #Loading 元素,因为它位于 #searchContainer 内部。

请改用 append()

function(data) {  
    $("#Loading").hide(); 
    $("#searchContainer").append(data.d[0]);
}

或者只需将 #Loading 元素移到 #searchContainer 元素之外。


编辑:

我猜您没有名为#ajax-query-place的元素。

你应该使用:

$("#searchContainer").ajaxStart(function() {
     $("#Loading").show();
});

The trouble is in your success: callback. When you do:

$("#searchContainer").html(data.d[0]);

You are overwriting the #Loading element because it is inside #searchContainer.

Use append() instead.

function(data) {  
    $("#Loading").hide(); 
    $("#searchContainer").append(data.d[0]);
}

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:

$("#searchContainer").ajaxStart(function() {
     $("#Loading").show();
});
爱要勇敢去追 2024-09-08 23:40:33

简单:在启动 ajax() 方法之前,显示旋转图像。在success方法中,再次隐藏。

Easy: Before launching the ajax()-methode, display the spinner image. In the success method, hide it again.

情丝乱 2024-09-08 23:40:33
$.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) { $("#searchContainer").html(data.d[0]);
                                            $("#loading-image").hide();
}});

$("#ajax-query-place").ajaxStart(function(){
      $("#loading-image").show();
});

$("#ajax-query-place") 是获取或发送 ajax 查询的元素。

$.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) { $("#searchContainer").html(data.d[0]);
                                            $("#loading-image").hide();
}});

$("#ajax-query-place").ajaxStart(function(){
      $("#loading-image").show();
});

$("#ajax-query-place") is an element which is getting or sending ajax queries.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文