0

嘿伙计们,我正在开发一个“状态”-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>
4

1 回答 1

0

看起来在您第一次调用此代码后,您正在破坏#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 之后创建了一个文档“就绪”事件?

我试图弄清楚你想要的效果。看起来您希望在上传完成后(在#showdiv 中)淡入淡出,等待几秒钟,然后再次淡出?(您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);
        });
    }); 
},
于 2009-11-10T04:43:44.483 回答