Ask Confirmation Before Call an Ajax request in Jquery

# HTML Button::

<button onclick="status_change(1)" >Call Ajax</button>

# JavaScript Code::

<script type="text/javascript">

function status_change(id) {
    $.confirm({
       'title' : 'Attention!',
       'message' : 'Want to Continue?',
       'buttons' : {
            'YES' : {
            'class' : 'blue',
            'action': function(){
                $('#loading').html('ring.gif'); 
                $.ajax({
                   type: "POST",
                   url: "url/"+id,
                   data:{ID:id},
                   success: function(msg){

                            window.location.reload();
                   }
               });
            }
         },
         'NO' : {
            'class' : 'gray',
            'action': function(){
                 return false;
            } 
              // Nothing to do in this case. You can as well omit the   action property.
       }
    }
 });

}
</script>

Leave a Reply

Your email address will not be published. Required fields are marked *