2009-08-08 91 views
1

如何獲得當前父DIV ID提交表單與我沒有與成功狀態多形式的頁面提交與給ajaxForm()

感謝您的任何問題給ajaxForm插件

下面是我的代碼。

<script type="text/javascript" charset="utf-8"> 
$('.formsubmit').ajaxForm({ 

    beforeSubmit: function() { 
     // here want form parent div display loading.. 
     var id = $(this).parent().id; // my problem here how to get current action form parent div id 
     $('div#'+id).html("Loading..."); 
    }, 
    url: '/post.php', 
    success: Response, 
    datatype: ($.browser.msie) ? "text" : "xml" 
}); 
function Response(xml) { 
    // let say XML return is equal 1 
    var id = xml; 
    $('div#'+id).html("Success"); 
} 
</script> 

<html> 
<body> 
<div id="1"> 
    <form class='formsubmit' action='/post.php' method='post'> 
     <input name='url' value='stackoverflow.com'> 
    </form> 
</div> 
<div id="2"> 
    <form class='formsubmit' action='/post.php' method='post'> 
     <input name='url' value='jquery.com'> 
    </form> 
</div> 
<div id="3"> 
    <form class='formsubmit' action='/post.php' method='post'> 
     <input name='url' value='google.com'> 
    </form> 
</div> 
</body> 
</html> 

回答

3

從我可以在docs看到,beforeSubmit方法被調用有三個PARAMS:以陣列形式

  • 形式數據
  • jQuery對象的形式
  • 選項傳入ajaxForm/ajaxSubmit的對象

鑑於如果您chan GE你之前提交給

beforeSubmit: function(formData, formObj, options) { 
    var id = formObj.parent().attr('id'); 
    $('div#'+id).html("Loading..."); 
} 

這應該工作,雖然我沒有測試它。

+0

就像你說的那樣工作。非常感謝。 – Paisal 2009-08-10 01:54:03