2009-11-09 54 views
0

嘿傢伙,我正在研究「狀態」 - 更新。它的工作原理,只有一個問題,發送狀態後,我必須手動重新加載頁面,讓腳本再次運行。你能幫我嗎?這裏是代碼:JQuery - 編碼問題

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

我可以澄清一下,在你成功的回調(在發送到request.php後)你想再次加載(GET)這個同樣的request.php嗎?當你開機自檢時,有沒有想要處理的某種迴應? (目前我沒有看到正在使用的響應。) – Funka 2009-11-09 21:29:28

+0

那麼,文件「request.php」看起來像這樣(當下!):

Erfolgreich eingetragen!
PHP部分即將推出。我想要達到的,如果我點擊提交按鈕,jQuery代碼的作品。那麼,它的工作原理,但只是一次。在第一次點擊提交按鈕後,腳本應該像第一次那樣工作。但如果我第二次點擊提交按鈕,沒有任何工作。無論如何:我希望腳本經常工作,我點擊提交按鈕....希望你瞭解我。我的英語不是最好的...(我是德語...) – Kaley 2009-11-09 21:38:09

+0

因此,點擊提交按鈕發佈到您的PHP頁面,然後立即獲取PHP頁面? (兩個請求/響應?) – Funka 2009-11-10 04:37:38

回答

0

它看起來像你第一次調用此代碼後,你摧毀#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); 
     }); 
    }); 
}, 
+0

非常感謝!有用!非常感謝!我很開心!我一直在這2天工作......我只是一個初學者:S – Kaley 2009-11-10 11:52:01