0

読み込み中の gif を表示し、ajax スクリプトの読み込みが完了したときに非表示にする方法をいくつか試しました。私は $j(window).load を試しましたが、現在、別の場所でロード中の gif div 要素に hide() 関数を配置しようとしています。関数内の他のスクリプトが読み込まれるまで、読み込み中の gif を表示する方法がわかりません。私に何ができるかわかりますか?(すべての $j('#loading'). hide() をコメントアウトすると、実際に読み込み中の gif が表示されます)。SimpleWithAttrPrices 関数は ajax スクリプトを実行し、値を返します。

function updatePrices(IDs){
    var product_id= <?=$product_id ?>;
    var qty= parseInt($j("#qtyUpdateBox input").val());
    $j('#loading').show();

    if (qty==1){
        function sendRequest(i,basePrice) {
            var optionSelectionArray = currentlySelectedAttributes(IDs[i]);
            simpleWithAttrPrice(optionSelectionArray, function(data) {
                //var vendor = IDs[i];
                var basePrice = parseFloat(roundDollar(data));
                $j('.details'+IDs[i]+ ' .priceBlock').empty();      
                $j('.details'+IDs[i]+ ' .priceBlock').append('<span>'+formatCurrency(basePrice,"$")+'</span>');
                $j('.details'+IDs[i]+ ' .priceBlock').append('<input type="hidden" name="customPrice" value="' + basePrice + '"/>');
            });
        }//end sendRequest

        for(i=0; i<IDs.length; i++)
        {   
            sendRequest(i);
            if(i=IDs.length-1){
                $j('#loading').hide();
            }
        }

        //$j('#loading').hide();
}//end if
//... THE REST OF THE FUNCTION NOT APPLICABLE
4

2 に答える 2

2

ajaxStart()ajaxStop()を使用して、ajax リクエスト中にロード アニメーションを表示/非表示にすることができます。

これは次のように簡単です。

$(document).ajaxStart(function() {
  $j('#loading').show();
})
.ajaxStop(function() {
  $j('#loading').hide();
});
于 2013-06-11T03:18:35.730 に答える
0

送信したリクエストの数を簡単に追跡できる場合は、要素を非表示.ajaxSuccess()にする前に、呼び出された回数を数えることができます。#loading

于 2013-06-11T03:19:27.487 に答える