将数组值从jquery ajax传递到php函数调用 [英] passing array value from jquery ajax to php function call

查看:101
本文介绍了将数组值从jquery ajax传递到php函数调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有10个复选框,当我想删除用于选择一个或多个复选框的适当记录时.所有复选框名都是数组.我正确地从html页面到jquery函数获取值.之后,我将所有选中的框放入jQuery函数中创建的数组中.但是我无法将值从此jquery函数发送到ajax php函数.可能是我尝试的方式将是错误的.请在下面查看我的代码.

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 function 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);
    }
}

我没有收到任何错误.但同时它总是返回1.

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

推荐答案

您可能需要序列化您的表单数据,然后将整个数据传递给您的PHP脚本.在这种情况下,您将能够知道受影响的行数.

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.

这篇关于将数组值从jquery ajax传递到php函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆