2015-12-02 243 views
1

我確認了提交值並獲得成功提醒後,我創建了一個輸入框,但我也取消了取消按鈕的成功?Ajax在這兩種情況下運行

swal({ 
    title: " Asking price for " + askData[0] + "?", 
    text: "If you are sure press OK or edit this text", 
    type: "input", 
    inputType: "text", 
    inputValue: "Hello " + askData[1] + ", I am interested in buying your " + askData[0] + " of Variety :" + askData[3] + ". Please update the Price!", 
    showCancelButton: true, 
    closeOnConfirm: false, 
    showLoaderOnConfirm: true 
}, function (inputValue) { 
    if (inputValue === "") { 
     swal.showInputError("Please write something !"); 
     return false; 
    } 
    $.ajax({ 
     url: urlEnq, 
     type: "GET" 
    }); 
    $.ajax({ 
     url: 'saveUserMessage', 
     type: "POST", 
     data: { 
      fieldUserId: fieldUserId, 
      filedUserCompanyId: filedUserCompanyId, 
      message: inputValue 
     }, 

    }) 
     .done(function (data) { 
      swal("Done!", "Your message has been successfully sent.", "success"); 
     }) 
     .error(function (data) { 
      swal.showInputError("Please write something !"); 
     }); 
+3

什麼是'inputValue'可變的,當您單擊取消的價值? –

+0

inputValue用於輸入值字段,一個文本框。 –

+0

是的,我們知道變量的實際值是多少?你正在做一個如果在該變量,以決定是否需要做阿賈克斯調用 –

回答

1

當使用SweetAlert傳遞到回調函數的變量的值將是false和不''被點擊時取消。

我已經更新您的jsfiddle顯示此,請參見下面的更新的代碼:

$('button.delete-account').click(function (e) { 
    swal({ 
     title: "Are you sure you want to delete your account?", 
     text: "If you are sure, type in your password:", 
     type: "input", 
     inputType: "password", 
     showCancelButton: true, 
     closeOnConfirm: false 
    }, function (typedPassword) { 
     if (typedPassword === false) { 
      return; 
     } 
     if (typedPassword === "") { 
      swal.showInputError("You need to type in your password in order to do this!"); 
      return false; 
     } 
     $.ajax({ 
      url: "/api/delete-account", 
      data: { password: typedPassword }, 
      type: "POST" 
     }).done(function (data) { 
      swal("Deleted!", "Your account has been deleted!", "success"); 
     }).error(function (data) { 
      swal.showInputError("Your password is wrong!"); 
     }); 
    }); 
}); 
+0

謝謝工作現在。 –