質問

やあみんな、私は「ステータス」-Updaterに取り組んでいます。それはちょうど一つの問題は、再びスクリプトを動作させるために手動リロードにページを私が持っているステータスを送信した後、そこにある、動作します。あなたは私を助けてくださいすることができますか?ここでは、コードがあります:

<script language="javascript">
$(document).ready(function(){
    $("form#status_form").submit(function(){
        var s_autor =   $('#s_autor').attr('value');
        var s_status    =   $('#s_status').attr('value');
        $.ajax({
            type: "POST",
            url: "/admin/request.php",
            data: "s_autor="+ s_autor +"& s_status="+ s_status,
            success: function(){
                $('#show').load("/admin/request.php").fadeIn("slow", function(){
                    setTimeout(function(){
                        $(function() {
                             $("#show").fadeTo("slow", 0.01, function(){
                                 $(this).slideUp("slow", function() {
                                     $(this).remove();
                                 });
                             });
                        });
                    }, 2000);
                });
            },
        });
        return false;
    });
});
</script>

だから、私は、送信ボタンをクリックする頻度スクリプトを繰り返すことを可能にし、それをコーディングする方法を知っていますか?

ところで、ここではHTMLフォームがあります:

<form id="status_form" method="post" action="request.php" onsubmit="return false;">
    <input type="text" id="s_autor" name="s_autor" value="<?= $user_id; ?>" style="display: none;" /><input type="text" id="s_status" name="s_status" value="Statusnachricht" /><input type="submit" value="" class="submit" id="status_submit" />
</form>
役に立ちましたか?

解決

このコードを呼び出すあなたの最初の時間の後、あなたは#showを破壊しているように見えます、したがって、次回は、これ以上#showはありませんか?私は私がこの正しく理解してるかどうかを確認するために、あなたのコードにいくつかのコメントを追加するつもりです。

success: function() {
    // File has been successfully posted to request.php
    // We are now going to GET the contents of request.php (ignoring any response from the previous POST)
    // Also note, should probably put remainder of code in a callback to "load", so we can be sure it has had a chance to load!...
    $('#show').load("/admin/request.php").fadeIn("slow", function(){
        setTimeout(function(){
            $(function() {
                 $("#show").fadeTo("slow", 0.01, function(){
                     $(this).slideUp("slow", function() {
                         // Note! #show is being removed from the document here. It won't be available for future events.
                         $(this).remove();
                     });
                 });
            });
        }, 2000);
    });
},

グッドラック!

もう少しこのを見てたら、

編集、私はあなたがあなたのsetTimeout後の文書「準備完了」イベントを作成している気づいた?

私は、あなたが望む効果を把握しようとしています。あなたが何かをしたいようですが、数秒待って、(#show divの中で)アップロードが終了した後にフェードインに見え、その後、再びそれをフェードアウト? (あなたのslideUpがフェードアウト要素に作用しているので、効果が見られません。)

どのようにこのようなものでしょうか?

success: function() {
    // File has been successfully posted to request.php
    // We are now going to GET the contents of request.php (ignoring any response from the previous POST)
    $('#show').load("/admin/request.php", function() {
        $(this).fadeIn("slow", function() {
            setTimeout(function() {

                $("#show").fadeOut("slow", function() {
                    // don't remove #show. Just empty it for using again next time.
                    $(this).empty()
                });

            }, 2000);
        });
    }); 
},
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top