开发者

passing array value from jquery ajax to php function call

开发者 https://www.devze.com 2023-02-17 22:46 出处:网络
I have a 10 checkboxes, when i want to delete the appropriate record I use to select one or more checkbox. All the checkbox nams are array. I\'m properly getting the values from the html page to jquer

I have a 10 checkboxes, when i want to delete the appropriate record I use to select one or more checkbox. All the checkbox nams are array. I'm properly getting the values from the html page to jquery function. After that i pushed all the checked boxes into the array created in the jQuery function. But i'm not able to sent the values from this jquery fun开发者_运维百科ction to the ajax php function. May be the way i'm trying will be wrong. Please check out my code below.

function BulkDelete()// jQuery Function
{
    var Selected = new Array();
    jQuery("input[name='chec[]']:checked").each(function(){
        Selected.push(jQuery(this).val());
    });

    jQuery.ajax({
        url:"<?php echo admin_url( 'admin-ajax.php' ); ?>",
        type:"POST",
        data:"action=doctor_management_add_dept&id="+ Selected +"&task=bulkdelete",
        success:function(data){
            jQuery("#msg").html("<div id='message'>"+data+"</div>");
        }
    });               
}

function doctor_management_add_dept() // PHP function
{
    if($_POST['task']=="bulkdelete") {
        $ars[] = $_POST['id'];
        echo count($ars);
    }
}

I'm not getting any error. But the same time it's always returning 1.


You may want to serialize your form data, then pass a whole one to your PHP script. In this case, you'll be able to tell how many rows affected.

0

精彩评论

暂无评论...
验证码 换一张
取 消