0
我想顯示一個確認對話框,如果用戶按'繼續',表單將被提交。ajax表單提交使用jQuery對話框
這是jQuery代碼:
$(document).ready(function() {
$('#submit').click(function() {
$('#confirmation-dialog').dialog('open');
return false; // prevents the default behaviour
});
$('#confirmation-dialog').dialog({
autoOpen: false, width: 400, resizable: false, modal: true, //Dialog options
buttons: {
"Continue": function() {
$(this).dialog('close');
var form = $('transferForm', this);
$(form).submit();
return true;
},
"Cancel": function() {
$(this).dialog("close");
return false;
}
}
});
});
這是形式:
@using (Ajax.BeginForm("Transfer", "Location", null, new AjaxOptions
{
UpdateTargetId = "update-message",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
//OnBegin = "ajaxValidate",
OnSuccess = "updateSuccess"
}, new { @id = "transferForm" }))
{
<div style="width:600px;">
<div class="editorLabel">
@Html.LabelFor(m => m.FromEmail)
</div>
<div class="editorText">
@Html.TextBoxFor(m => m.FromEmail)
</div>
<div class="clear"></div>
<div class="editorLabel">
@Html.LabelFor(m => m.ToEmail)
</div>
<div class="editorText">
@Html.TextBoxFor(m => m.ToEmail)
</div>
<div class="clear"></div>
<p>
<input type="submit" name="submit" value="Transfer" class="btn" id="submit"/>
</p>
</div>
}
<div id="update-message"></div>
<div id="commonMessage"></div>
<div id="confirmation-dialog">
<p>Are you sure you want to proceed with transfer ?
</p>
</div>
但確認後,表單沒有提交。 這裏有什麼可能是錯誤的?有任何想法嗎??
你使用了一個錯誤的jquery選擇器 - var form = $('transferForm',this);不應該是var form = $('#transferForm',this); – aravind