1

次のコードでは、ajax リクエストの前に div を表示しようとしており、完了後に div を非表示にしたいと考えています。hide() は正常に動作していますが、show() は動作していません。Firefoxでうまく機能します。

$("#btnpst").click(function () {
   $('#dvloading').show();
   $.ajax({
       url: url,
       type: "POST",
       async: false,
       contentType: "application/json; charset=utf-8",
       dataType: "json",
       success: function (data, st) {
           if (st == "success") {
               $('#dvloading').hide();
           }
       },
       error: function () {
           $('#dvloading').hide();
       }
   });
   } //<
});

HTML

<div id="dvloading" style="width: 480px; height: 320px; position: absolute; overflow: hidden;">
    <image src="../loading_2.gif" style="margin-top: 120px;">
</div>
4

2 に答える 2

0

あなたがテストしているのはローカルであり、応答はかなり速いと思います。この行を変更しない理由

$('#dvloading').hide();

これに

setTimeout(function(){$('#dvloading').hide();},5000);

そうであるかどうかを確認します。また、javascript コンソールから js 関連のエラーがないかどうかを確認することも役に立ちます。

于 2012-08-10T05:58:46.437 に答える
0

"If I put alert above hide() I am able to see it". "without alert it's not visible. ajax call is taking about 10 sec"

these two statements somehow seem contradictory, if your DIV is actually shown and then hidden and the ajax call takes about 10 seconds, it should appear so without the alert box also.. I really doubt whether the ajax call takes about 10 sec..

Here is a fiddle to illustrate your scenario, i have removed the content type attribute from the ajax call and used flickr's json response page. its working fine.

jsfiddle

于 2012-08-10T20:34:17.160 に答える