Ajax Confirm Button Example - Jquery

How to confirm before ajax request?

Snippet Code


  
Rate this page :
  [ 0 votes]

Confirm button is used to create an confirmation messages when you click the button to perform some action. Here, the sample code to create confirm box before sending ajax request is given below.

<script src='http://code.jquery.com/jquery-2.1.0.min.js'></script> <script> function testconfirm(id) { if (confirm("Click OK to submit?")) { $.ajax({ url: 'test.php', type: 'post', data: {'id' : id}, success: function(data) { alert(data); } }); } } </script> <input type='button' onclick='testconfirm("7")' value='Click To Get Id'> test.php: ---------- <?php error_reporting(0); $id = $_POST[id]; echo "Your id is: ".$id; ?>

Tags


Ask Questions

Ask Question