1

我正在使用ajax,有时从我的数据库中加载所有数据需要时间,因此我需要找到一种方法来显示(正在加载...),而数据尚未完成。下面是我的示例代码,我正在寻找数据仍在处理中的一些事件。

$.ajax({
   type: "POST",
   url: "some.php",
   data: "name=John&location=Boston",
   success: function(data){
     $('#para').html(data);
   }
 });
4

3 回答 3

1

It is very simple..

before you call the ajax start your loading image..& after the success hide the image for eg :

$.fancybox.showLoading();
$.ajax({
   type: "POST",
   url: "some.php",
   data: "name=John&location=Boston",
   success: function(data){
     $.fancybox.hideLoading();
     $('#para').html(data);
   }
});

here

$.fancybox.showLoading()

is my function in which I have the property of displaying the loader,

于 2013-04-20T07:17:59.377 回答
0

This will be internally called whenever an ajax call is made.

$.ajaxStart(function() {
    $("img#loading").show();
});

$.ajaxComplete(function() {
    $("img#loading").hide();
});

HTML

<img src="../images/loading.gif" alt="wait" id="loading"/>
于 2013-04-20T07:18:44.767 回答
0
<div id="loading">LOADING...</div>

var loading = $("#loading");

loading.hide();

function doAjax() {
    loading.show();
    $.ajax({
        url: "/js/beautifier.js",
        success: function (data) {
            loading.hide();
        }
    });
}

doAjax();

jsfiddle上

于 2013-04-20T07:21:58.287 回答