I am new developer and I have a problem. I think you can solved this. I want to show confirm box before delete. How Can I do that this my Ajax code
HTML:

<input type='button' class="btn btn-danger delete_button" id="delete_button<?php echo $row->id;?>" value="delete" onclick="delete_row('<?php echo $row->id;?>');">

ajax

function delete_row(id)
{
 jQuery.ajax({
    type:'post',
    url: "/blue_bucket/wp-admin/admin-ajax.php?action=delete_form",  
    data:{
            delete_row:'delete_row',
            row_id:id,
        },
    success:function(response) {
        if(response=="success")
            {
            var row=document.getElementById("row"+id);
            row.parentNode.removeChild(row);
            }
            top.location.href="admin.php?page=data_list";
    }
 });
}

WordPress PHP

function delete_form()
    {
        if(isset($_POST['delete_row']))

        {
        $id=$_POST['row_id'];
        echo $row_no;
        global $wpdb;
        $table_name = "countries";
        $wpdb->delete($table_name, 
                        array( 'id' => $id ) );
         exit();
        }

    }

    add_action( 'wp_ajax_delete_form', 'delete_form' );
    add_action('wp_ajax_nopriv_delete_form', 'delete_form');

Read more here: How to add confirm box before submit


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: