domi771
domi771

Reputation: 450

javascript ajax call before send is not executed

I have this Javascript code:

this.confirmBox = function(data) {
  $.jconfirm((function(_this) {
    return function() {
      var objConfig;
      objConfig = $.jconfirm("getConfig");
      alert("here");
      return true;
    };
  })(this));
  return false;
};

this.beforeSend = function(event, jqXHR) {
  if (this.confirmBox()) {
    return this.disableSubmit();
  } else {
    return jqXHR.abort();
  }
};

When I run the script I am landing on alert("here") and return true for the function confirmBox.

The problem however is that the ajax call itself is not triggered anymore for some reason. How do I need to adjust the beforeSend function in order to check if the checkBox result is true or false?

Upvotes: 1

Views: 195

Answers (2)

Mihir
Mihir

Reputation: 449

I think call to confirmBox method in beforeSend always returns false because $.msgbox does not block thread execution like window.confirm method does. Probably you need to invoke ajax call when you get the result === "Confirm" from message box.

$.msgbox("confirm", {
    type: "confirm",
    buttons: [
        { type: "cancel", value: "Cancel" }, 
        { type: "submit", value: "Confirm" }
    ]}, function(result) {
        if (result === "Confirm") {
            // $.ajax(..)
        }
    }
};

Upvotes: 1

Scription
Scription

Reputation: 645

You have to add the event on the buttons Please see this fiddle example

buttons: {
        "Yes": function () {
            $(this).dialog('close');
            callback(true);
        },
            "No": function () {
            $(this).dialog('close');
            callback(false);
        }
    }

Upvotes: 1

Related Questions