【发布时间】:2011-01-07 10:57:38
【问题描述】:
我使用本教程创建了一个模式弹出登录
现在这让我了解弹出的模态表单。当我点击我的提交按钮时没有任何反应(正常表单在不处于模式时工作正常),所以我的问题有两个:-
- 如何在我的帐户控制器中将提交发布到我的登录操作。
- 如何让任何验证错误显示在模式中?
这是本教程生成的脚本:-
(function ($) {
var alog = window.console ? console.log : alert;
$.fn.popUpForm = function (options) {
// REQUIRE a container
if (!options.container) { alert('Container Option Required'); return; }
// Give us someplace to attach forms
$("#popUpHide").length || $('<div id="popUpHide" />').appendTo('body').css('display', 'none');
// Defaults and options
var defaults = {
container: '',
modal: true,
resizeable: false,
width: 440,
title: 'Website Form',
beforeOpen: function (container) { },
onSuccess: function (container) { },
onError: function (container) { }
};
var opts = $.extend({}, defaults, options);
this.each(function () {
var $this = $(this);
if (!$this.is('a') || $this.attr('href') == '') { return; }
var SRC = $this.attr('href') + ' ' + opts.container;
var formDOM = $("<div />").load(SRC, function () {
$('#popUpHide').append(formDOM);
$(opts.container).dialog({
autoOpen: false,
width: opts.width,
modal: opts.modal,
resizable: opts.resizeable,
title: opts.title
});
$(opts.container).bind("submit", function (e) {
e.preventDefault();
ajaxSubmit($this[0]);
});
$this.bind("click", function (e) {
e.preventDefault();
opts.beforeOpen.call($this[0], opts.container);
$(opts.container).dialog('open');
});
});
});
function ajaxSubmit(anchorObj) {
console.log(anchorObj);
var form = $(opts.container);
var method = form.attr('method') || 'GET';
$.ajax({
type: method,
url: form.attr('action'),
data: form.serialize(),
success: function () {
$(opts.container).dialog('close');
opts.onSuccess.call(anchorObj, opts.container);
},
error: function () {
opts.onError.call(anchorObj, opts.container);
}
});
}
}
})(jQuery);
感谢您的任何想法,
丰富
【问题讨论】:
标签: jquery asp.net-mvc forms jquery-ui-dialog