2016-11-23 7 views
0

私は今、私は古典的な甘いアラートを使用して確認(送信)する方法

​​ を削除したいページの下部

$(document).on('submit', '[id^=tableDelete_]' , function() { 
return callAjax($(this).serialize()); 
}); 

function callAjax(data) { 
    $.ajax({ 
    type : 'POST', 
    url : 'call/page.php', 
    data : data, 
    success : function(data) { ... }, 
    error: function(data) { ... } 
    }); 
    return false; 
}; 

に、この後、各行は、このフォームで

<form id="tableDelete_1"> 
<input type="hidden" name="tipo" value="delete" /> 
<input type="submit" name="send" value="Delete" class="btn btn-danger btn-xs" onClick="return confirm(`Are you sure?`)" /> 
</form> 

<form id="tableDelete_2"> 
<input type="hidden" name="tipo" value="delete" /> 
<input type="submit" name="send" value="Delete" class="btn btn-danger btn-xs" onClick="return confirm(`Are you sure?`)" /> 
</form> 

を削除ボタンを持つテーブルを持っています

とsweetalertを使用してください... 私はこの機能でポップアップだけを表示したいときにちょっとした問題があります

$(document).on('submit', '[id^=tableDelete_]' , function() { 
swal({ 
    title: "Are you sure?", 
    text: "You will not be able to recover this imaginary file!", 
    type: "warning", 
    showCancelButton: true, 
    confirmButtonColor: "#DD6B55", 
    confirmButtonText: "Yes, delete it!", 
    closeOnConfirm: false 
}, 
function(){ 
    swal("Deleted!", "Your imaginary file has been deleted.", "success"); 
}); 
}; 

ポップアップが

は私はあなたがデフォルトを防ぐために必要

答えて

2

私が正しく読んだら、あなたはこのようなものを探していると思いますか?

$(document).on('submit', '[id^=tableDelete_]', function (e) { 
    e.preventDefault(); 

    var data = $(this).serialize(); 

    swal({ 
    title: "Are you sure?", 
    text: "You will not be able to recover this imaginary file!", 
    type: "warning", 
    showCancelButton: true, 
    confirmButtonColor: "#DD6B55", 
    confirmButtonText: "Yes, delete it!", 
    cancelButtonText: "No, cancel plx!", 
    closeOnConfirm: false, 
    closeOnCancel: false 
    }, 
    function (isConfirm) { 
     if (isConfirm) { 
     $.ajax({ 
      type: 'POST', 
      url: 'call/page.php', 
      data: data, 
      success: function (data) { 
      swal("Deleted!", "Your imaginary file has been deleted.", "success"); 
      }, 
      error: function (data) { 
      swal("NOT Deleted!", "Something blew up.", "error"); 
      } 
     }); 
     } else { 
     swal("Cancelled", "Your imaginary file is safe :)", "error"); 
     } 
    }); 

    return false; 
}); 
+0

e.preventDefault()でポップアップが表示されません...返品虚偽でOK! 残りの機能をありがとう – FireFoxII

0
$(document).on('submit', '[id^=tableDelete_]' , function(e) { 
e.preventDefault(); 
//do your popup stuff 
return false 
}); 

助けて与えてください...私は、フォームが送信されると思うので、そのページがリロードされる第二のためにのみ示されていますイベント(eとして渡される)が発生したときに発生するイベント。

+0

を! – FireFoxII

+0

非常に興味深い –

1

SweetAlertが確認コールバックの約束使用しています:ポップアップがこのWhitout ...示したが、偽のリターンで私は問題を解決されません)(e.preventDefaultで

swal({ 
     title: "Confirm?", 
     text: "Are you sure?", 
     type: "warning", 
     showCancelButton: true, 
     confirmButtonColor: "#DD6B55", 
     confirmButtonText: "Confirm", 
     cancelButtonText: "Back" 
     } 
    ).then(
     function (isConfirm) { 
     if (isConfirm) { 
      console.log('CONFIRMED'); 
     } 
     }, 
     function() { 
     console.log('BACK'); 
     } 
    ); 
関連する問題