How can I close the jquery ui dialog when I submit the form?

I load the form into the jquery ui dialog. I have a submit button ( inside my form - NOT the actual dialog buttons ) that triggers the controller action, but I cannot figure out how to close the dialog after the submit call, since I don't have an event handler that I attach.

is there anything to do besides changing the submit to input type = button?

I know that in jquery I can capture submit

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

but it looks like a fire before sending, so I don’t want to close the dialog yet.

There is something wrong with the code below:

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

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

    closeModalPopup();
    return false ;
});
+3
source share
2 answers

: success, :

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

: submit, :

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

.

+5

, $("#name_of_the_dialog").dialog( "" );

, $closest

0

Source: https://habr.com/ru/post/1763799/


All Articles