mardi 18 octobre 2016

How to delete multiple using checkbox with Ajax call

list form i am trying to delete values with check box using ajax call can any one help me out.

unable to find the error and one nore thing this is a template and i hav a feature of check all inbuilt so do need to change anyinbuilt code for check box This is my listing form:

<form id="stafflistForm">
<input type="hidden" name="checkedids" value="<?php echo $staffResults['id_staff']; ?>">
<button id="deleteChecked"><i class="fa fa-trash-o"></i></button>
</form>

This my Ajax Script:

<script language="JavaScript">  
    $("#deleteChecked").click(function()
    {
        $("#delshowMessageDiv").hide();
        $("#delshowMessage").html('');
        $.ajax({
            url: "staffcontroller.php",
            method: "POST",
            data: { delData : $("#stafflistForm").serialize(), 'action':'delete'},
            dataType: "json",
            success: function (response) {
                if(response["success"]==true)
                {
                    $("#delshowMessageDiv").hide();
                    $("#delshowSuccessMessageDiv").show();
                    $("#delshowSuccessMessage").html(response["message"]);
                    }else{
                    $("#delshowMessageDiv").show();
                    $("#delshowMessage").html(response["message"]);
                }   
            },
            error: function (request, status, error) {
                $("#hshowMessageDiv").show();
                $("#hshowMessage").html("OOPS! Something Went Wrong Please Try After Sometime!");
            }
        });
        return false;
    });     
</script>

And this is my controller page:

else if($_REQUEST['action']=='delete'){
    $delids=explode(",",$_REQUEST["checkedids"]);
    $count=count($delids);
    for($i=0;$i<$count;$i++)
    {
        $delQuery= $conn->query("DELETE FROM os_staff WHERE id_staff=".$delids[$i]);
    }
        if($delQuery){
        $response['message'] = "<strong>Success!</strong>Staff Deleted Successfully.";
        $response['success'] = true;
        }else{
        $response['message'] = "<strong>Warning!</strong> Staff Not Deleted.Please Check Carefully..";
        $response['success'] = false;
    }
    echo json_encode($response);
    exit;
}




Aucun commentaire:

Enregistrer un commentaire