多形式的页面提交与给ajaxForm()
问题描述:
如何获得当前父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='*.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>
答
从我可以在docs看到,beforeSubmit
方法被调用有三个PARAMS:以阵列形式
- 形式数据
- jQuery对象的形式
- 选项传入ajaxForm/ajaxSubmit的对象
鉴于如果您chan GE你之前提交给
beforeSubmit: function(formData, formObj, options) {
var id = formObj.parent().attr('id');
$('div#'+id).html("Loading...");
}
这应该工作,虽然我没有测试它。
就像你说的那样工作。非常感谢。 – Paisal 2009-08-10 01:54:03