dongxue9997 2017-08-10 14:18
浏览 53
已采纳

PHP Ajax发送数组

I'm sending an array to a PHP file named update.php and in all previous versions of this script it's worked, but for some bizarre reason it isn't working in this instance.

Here are the files:

var phpLocation = '/admin/_backend' + $( this ).attr("action"),
    usergroup = $('input:hidden[name="usergroup"]').val(),
    serializedData = $('input:checkbox[name="permission"]:checked').map(function () {
                         return this.value;
                      }).get();

var ajaxData = {'usergroup_permissions': serializedData, 'usergroup' : usergroup};

$.ajax({
    type: "POST",
    url: phpLocation,
    data: ajaxData,
    success: function(data){
        $("#post_reply").html(data);

        console.log( ajaxData );
    }
});

When attempting to grab and turn usergroup_permissions from an array into a list separated by commas, it doesn't seem to work.

Even when using $_POST['usergroup_permissons'] it doesn't seem to work..

$permission_list = implode(",", $_POST['usergroup_permissions']);

Edit
This is the console.log output
enter image description here

print_r( $_POST ); returns:

enter image description here

  • 写回答

1条回答 默认 最新

  • dsajkdadsa14222 2017-08-10 14:54
    关注

    I worked out that somewhere else in the script I am calling a serialize of the whole form and so the permission in the second image is coming from that (because it's the name of the checkbox).

    I've now rectified this and it is working fine.

    Thank you very much for all of your help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计