簡體   English   中英

發送前的javascript ajax調用未執行

[英]javascript ajax call before send is not executed

我有這個Javascript代碼:

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

當我運行腳本時,我將登陸到alert("here")並為函數ConfirmBox return true

但是問題是,由於某種原因,不再觸發ajax調用本身。 我需要如何調整beforeSend函數以檢查checkBox結果是true還是false?

我認為在beforeSend中對ConfirmBox方法的調用始終返回false,因為$ .msgbox不會像window.confirm方法那樣阻止線程執行。 從消息框中獲得結果===“ Confirm”時,可能需要調用ajax調用。

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

你要添加的按鈕的情況,請參見小提琴例子

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM