Jquery deferred object

Defer an action until later.

Typescript example using JQuery.Deferred

function SaveComment(msg) : JQueryDeferred<any> {
  var dfd = jQuery.Deferred();
  $.ajax({
      url: "/some/url",
      data: {
          Message: msg
      },
      method: "POST",
      dataType: "json",
      // uncomment contentType if the response is json
      // contentType: "application/json; charset=utf-8",
      success: function (result) {
          // With data
          // dfd.resolve(result);
          
          // Without data
          dfd.resolve();
      },
      error: function (xhr, textStatus, errorThrown) {
          dfd.reject();
      }
  });

  return dfd;
}

Calling the SaveComment function

SaveComment("My comment")
  .done(function () {
      alert("The SaveComment function ajax call has finished");
  });