Jquery dialog not opening second time

纵然是瞬间 提交于 2019-12-13 03:35:32

问题


Before dismissing this as a question that has already been answered, please have a look. I have implemented pretty much all the solutions provided in the other posts, with no luck. The modal opens perfectly the first time, but fails the second time.

Modal is called from here:

function myFx(id){
  $.ajax(
    {
      type: "POST",
      url: "/mypath",
      data: { ZoneId: id },
      dataType: "json",
      success: function (data) {
        $('#dialog-form').dialog('open');
      }
    },
    error: function (response) {
    }
  });
 }

The function is inside $(document).ready(). No errors on firebug. On a button click, I call myFx() and pass id: <button onclick="myFx(id)" />.

And was initialised like this:

var myModal =  $('#dialog-form').dialog(
  {
    autoOpen: false,
    modal: true,
    height: 290,
    width: 475,
    buttons: {
      'Save': function () {
        $.ajax({
          type: "POST",
          url: $("#edit-book").attr('action'),
          data: $("#edit-book").serialize()+'&eZoneId=' +$('#eZoneId').val(),
          dataType: "text/plain",
          success: function (response) {
            var closeDialog = $('#dialog-form').dialog('close');
            $("#grid").load('mypath/ #grid', function () {
            $('tbody > tr:first')
              .effect("highlight", {}, 2000);
        });
      },
      error: function (response) {
        alert(response);
        $('#dialog-form').dialog('close');
      }
    });
  },
  Cancel: function () {
    $('#dialog-form').dialog('close');
  }
});

Please help.


回答1:


you need to put the below line before ajax call.

$('#dialog-form').dialog('open');


来源:https://stackoverflow.com/questions/17039654/jquery-dialog-not-opening-second-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!