2017-02-06 57 views
0

我需要在執行此ajax請求之前顯示確認框。如何在刪除記錄之前顯示確認框

$(document).on("click", ".deletecustomer", function() { 
    var id = $(this).attr("id"); 
    $.ajax({ 
     method: "post", 
     url: "deletecustomer.php", 
     data: { 
      id: id 
     }, 
     success: function(data) { 
      console.log(data); 
      if (data == "success") { 
       window.location.href = "customer.php"; 
      } 
     } 
    }); 
}); 
+1

'如果(確認( '你確定嗎?')){/ *阿賈克斯* /}'? – Qirel

回答

0
$(document).on("click", ".deletecustomer", function() { 
    if (confirm('Are you sure?')) { 
     var id = $(this).attr("id"); 
     $.ajax({ 
      method: "post", 
      url: "deletecustomer.php", 
      data: { 
       id: id 
      }, 
      success: function(data) { 
       console.log(data); 
       if (data == "success") { 
        window.location.href = "customer.php"; 
       } 
      } 
     }); 
    } 
}); 
+0

謝謝!現在工作正確... – user7525616

+0

好極了,如果它回答了你的問題,你可以繼續並將此答案標記爲完整嗎? –