tags:

views:

55

answers:

1

Hey guys, I'm working on a "status"-Updater. It works, there is just one problem, after sending a Status I have to manual reload the page to let the script work again. Do you can help me please? Here's the code:

<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>

So do you know how to code it to make it possible to repeat the script how often I click on the submit button?

By the way, here's the HTML-Form:

<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>
A: 

It looks like after your first time calling this code, you are destroying #show, and thus, the next time, there is no more #show? I'm going to add some comments to your code to see if i'm understanding this correctly:

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);
    });
},

Good luck!

EDIT Upon looking at this some more, I noticed you are creating a document "ready" event after your setTimeout?

I'm trying to figure out the effect you want. It looks like you want to have something fade in after the upload finishes (in the #show div), wait a few seconds, then fade it out again? (Your slideUp is acting on a faded-out element, so the effect won't be seen.)

How about something like this?

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);
        });
    }); 
},
Funka
THANKS A LOT! It works! Thanks so much! I'm so happy about it! I've been working on this 2 days... I'm just a beginner : S
Kaley