最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how can i close my jquery ui dialog when i submit a form? - Stack Overflow

programmeradmin0浏览0评论

i load a form into a jquery ui dialog. i have a submit button (inside my form - NOT the actual dialog buttons) that calls a controller action but i can't figure out how to close the dialog after the submit is called as i dont have any event handler that i am attaching.

is there anyway of doing this besides changing the submit to input type=button?

i know in jquery i can capture the submit

$('#positionForm').submit(function () {
    // do stuff
    return true;
});

but this seems to fire before submitting so i dont want to close the dialog yet.

is there anything wrong with the below code:

$('#positionForm').live('submit', function () {

    $.post('/MyController/Action', $("#positionForm").serialize(), function (data) {
            alert(data);
    }, "html");

    closeModalPopup();
    return false ;
});

i load a form into a jquery ui dialog. i have a submit button (inside my form - NOT the actual dialog buttons) that calls a controller action but i can't figure out how to close the dialog after the submit is called as i dont have any event handler that i am attaching.

is there anyway of doing this besides changing the submit to input type=button?

i know in jquery i can capture the submit

$('#positionForm').submit(function () {
    // do stuff
    return true;
});

but this seems to fire before submitting so i dont want to close the dialog yet.

is there anything wrong with the below code:

$('#positionForm').live('submit', function () {

    $.post('/MyController/Action', $("#positionForm").serialize(), function (data) {
            alert(data);
    }, "html");

    closeModalPopup();
    return false ;
});
Share Improve this question edited Sep 8, 2010 at 14:13 leora asked Sep 8, 2010 at 13:34 leoraleora 197k368 gold badges906 silver badges1.4k bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

For updated question: You can call the close code in the success callback, like this:

$('#positionForm').live('submit', function () {
  $.post('/MyController/Action', $(this).serialize(), function(data) {
    $('#positionForm').closest(".ui-dialog-content").dialog("close");
  }, "html");
  return false;
});

Original Answer: You can attach a form submit handler, for example:

$("#myform").submit(function() {
  $(this).closest(".ui-dialog-content").dialog("close");
});

You can give it a try here.

You can also do it using $("#name_of_the_dialog").dialog("close");

It's more natural than using $closest

发布评论

评论列表(0)

  1. 暂无评论