在$ .Ajax done函数中捕获jQuery Dialog close事件

时间:2015-04-17 10:09:30

标签: javascript ajax asp.net-mvc asp.net-ajax jquery-dialog

我使用jQuery Dialog构建了通用jQuery插件来显示消息。现在这被称为我的jQuery $ .ajax - > done函数。我需要捕获.ajax函数中的Dialog close事件,以便我可以相应地重定向页面。我是如何实现这一目标的?

Ajax功能

$('#NewFunctionNavigationForm').submit(function (e) {

   e.preventDefault();

  var DataToPost =  JSON.stringify($('#NewFunctionNavigationForm').serializeObject());

  var formURL = $(this).attr("action");

  $.ajax({
      type: "POST",
      url: formURL,
      dataType: "JSON",
      contentType: "application/json; charset=utf-8",
      data: DataToPost,
  })
.done(function (data, textStatus, jqXHR) {

    alert("Success: " + data.Response);

    $(this).MyMessageDialog({
        _messageBlockID: "_StatusMessage",
        _messageContent: "ccc"
    });
      ????????????? i need to capture dialog close event here??
    window.location = "/SystemCore/SystemCoreHome";
})
.fail(function (jqXHR, textStatus, errorThrown) { alert("Error"); })
.always(function (jqXHROrData, textStatus, jqXHROrErrorThrown) { alert("complete"); });

});

消息对话框插件

function ($) {
   var _messageWrap = {
    _messageBlockID: "",
    _messageContent: ""
   };
$.fn.MyMessageDialog = function (_messageWrap) {

    alert("from plugin  "+_messageWrap._messageBlockID + "  " + _messageWrap._messageContent);

    $("#" + _messageWrap._messageBlockID).text(_messageWrap._messageContent);


    if($("#"+_messageWrap._messageBlockID).length) //check if div with given ID exists
    {

        $("#" + _messageWrap._messageBlockID).dialog({
            modal: true,
            autoOpen: false,
            buttons: {
                Ok: function () {
                    $(this).dialog("close");
                }
            },
            width: "50%",
        });

        //clear existing content if there are any in given Div
        $("#" + _messageWrap._messageBlockID).html("");

        //add content to div 
        $("#" + _messageWrap._messageBlockID).append(_messageWrap._messageContent);

        $("#" + _messageWrap._messageBlockID).dialog("open");
    }
    else
    {
        alert("not exist");
    }
};
 }(jQuery));

1 个答案:

答案 0 :(得分:0)

$('div#_StatusMessage').on('dialogclose', function (event) {            
        alert("dialog is close.. do your stuff here now");
});