Obtain the jQuery dialog's closure event within the $.Ajax completion function

I have developed a custom jQuery plugin that utilizes jQuery Dialog to showcase messages. Specifically, I am using it within my jQuery $.ajax -->done function. My goal is to capture the close event of the Dialog in the .ajax function so that I can redirect the page accordingly afterwards. How can I achieve this?

Ajax function

$('#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"
    });
      // 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"); });

});

Message Dialog Plugin

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));

Answer №1

$('section#_MessageStatus').on('dialogclose', function (event) {            
        alert("the dialog has been closed, time to take action!");
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using MongoDB map-reduce with Node.js: Incorporating intricate modules (along with their dependencies) into scopeObj

I am currently immersed in developing a complex map-reduce process for a mongodb database. To make the code more manageable, I have organized some intricate sections into modules that are then integrated into my map/reduce/finalize functions through my sco ...

The JQuery duplication process did not function as anticipated

This question builds on a previous one related to jQuery cloning and incrementing IDs. The issue is that when adding new elements, the IDs are not being generated in the correct sequence. For example, if the initial ID is expy-1, clicking "add more" should ...

Ensuring contact form accuracy using jQuery and PHP

Can't seem to figure out why I am always getting false from the PHP file even though my contact form validation with jQuery and PHP is working fine. Let me explain with my code: Here is the HTML: <form method='post'> <label& ...

What is the reason behind my difficulty in opening my dialog box modally using JavaScript?

I am looking to keep a dialog open while data is being fetched from the server. Here is the code I have written: (async()=>{ document.getElementById("dialog").showModal(); if(condition1 is true){ await server_call1(); } ...

Looking to streamline a JavaScript function, while also incorporating jQuery techniques

I've got this lengthy function for uploading photos using hidden iFrames, and while it does the job well, it's quite messy. I'm looking to simplify it into a cleaner function with fewer lines of code for easier maintenance. function simplif ...

The information submitted through the form is not displaying on the console after being gathered using the post method in Express

When attempting to add products using a form on the admin page, the data (including an image file) is not being displayed in the console as expected. Instead, the following message appears: "{} POST /admin/add-product - - ms - -" Below is th ...

Utilizing function arguments in ReactJS

Currently, I am in the process of learning ReactJs and have an inquiry about the code snippet below. Would someone be able to clarify the functionality of the removeTour code and why the id parameter is being used within the function? const removeTour = (i ...

The custom filter in AngularJS fails to activate when a click event occurs

I am trying to customize the filtering of my table data based on selected conditions from a dropdown menu. I have created an AngularJS custom filter and passed all the necessary parameters. The desired functionality is that if no conditions are selected, ...

Creating a personalized notification box that is compatible with various screen sizes and web browsers on android devices with the help of

After successfully implementing a custom alert box to hide the header with JavaScript, I encountered an issue when trying to use it on different browsers and Android devices. The alert box appeared misplaced on the page and was too big for certain Android ...

JavaScrip $("").text(); is a straightforward way to recognize and extract

At the moment, I am utilizing the jQuery script below: $("TD.info > font").text(); when this specific HTML structure is present on a webpage: <td class="info"> <font> 3001474535 </font> </td> I had the idea to tweak t ...

Utilizing the fs module in Node.js

Hello friends! Currently I am faced with an issue while trying to import the fs module in nodejs. Initially, I utilized require to import it like so: const fs = require('fs'); Everything was functioning smoothly until recently when it suddenly ...

What are the best practices for utilizing an array of routes?

I'm new to working with react but I noticed something strange. My routes are currently set up like this: <Main> <Route exact path="/home" component={Home} /> <Route exact path="/home1" com ...

Automatically update the div every few seconds and pause when it has loaded successfully

I am facing a challenge in creating a div that refreshes automatically every 10 seconds, but stops when it successfully loads. Here is the jQuery script I have developed: <script type="text/javascript"> $(document).ready(function(){ var j = jQuer ...

The title of the Electron application remains consistent

My application is being packaged using electron-packager, but it's not changing its name and still displays "Electron." It's supposed to use the productName in my package.json file, but for some reason, it doesn't change. Even after creati ...

What is the best way to convert a deeply nested PHP array/object into JSON format?

For those who want a shorter explanation, here it is: I have a JavaScript array filled with objects. Some properties of these objects contain arrays of objects, which in turn may have more arrays or objects nested within them. This results in 5 levels of n ...

Can you provide the specific URL for a Metacafe video to stream within a div container?

Could anyone assist me in finding the "Direct Url" to play metacafe videos within a div element? ...

Electron employee: Concealed BrowserWindow leads to delay in the interface

My worker runs in a hidden browser window and sends multiple requests simultaneously. However, these requests from the worker end up causing lag and freezes in the main browser window. Any suggestions for resolving this issue? ...

The EJS templating system

I am currently working on a node.js project and I have an ejs template file that utilizes templates for the header and footer. The structure of template.ejs is as follows: <%- include(header) %> main content <%- include(footer) %> <script ...

In Typescript, we can streamline this code by assigning a default value of `true` to `this.active` if `data.active

I am curious if there is a better way to write the statement mentioned in the title. Could it be improved with this.active = data.active || true? ...

Clicking on a JQuery dropdown menu will always result in it staying open

After creating a dropdown menu click, I noticed some strange behavior. When I click the dropdown button, the menu appears as expected. However, if I move my cursor away without clicking the button again, the dropdown menu disappears and behaves like a hove ...