简体   繁体   English

将数组值从jquery ajax传递到php函数调用

[英]passing array value from jquery ajax to php function call

I have a 10 checkboxes, when i want to delete the appropriate record I use to select one or more checkbox. 我有10个复选框,当我想删除用于选择一个或多个复选框的适当记录时。 All the checkbox nams are array. 所有复选框名都是数组。 I'm properly getting the values from the html page to jquery function. 我正确地从html页面到jquery函数获取值。 After that i pushed all the checked boxes into the array created in the jQuery function. 之后,我将所有选中的框放入jQuery函数创建的数组中。 But i'm not able to sent the values from this jquery function to the ajax php function. 但是我无法将值从此jquery函数发送到ajax php函数。 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. 但同时它总是返回1。

You may want to serialize your form data, then pass a whole one to your PHP script. 您可能需要序列化表单数据,然后将整个数据传递给您的PHP脚本。 In this case, you'll be able to tell how many rows affected. 在这种情况下,您将能够知道受影响的行数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM