使用ajax选中复选框时,发布值失败

我在尝试使用ajax选中复选框时尝试发布值,但失败了,代码对我来说似乎正确..在url上看起来像这样,但实际上不应该。


http://localhost/logsys/admin/roleaccess/%3C?%20$role[%27id%27];%20?%3E

我正在使用在xampp v 7.3.0上运行的codeigniter v 3.1.10


<script>

    $('.form-check-input').on('click', function() {

        const menuId = $(this).data('menu');

        const roleId = $(this).data('role');


        $.ajax({

            url: "<?= base_url('admin/changeaccess'); ?>",

            type: 'post',

            data: {

                menuId: menuId,

                roleId: roleId


            },

            success: function() {

                document.location.href = "<?= base_url('admin/roleaccess/'); ?>" + roleId;

            }

        });

    });

</script>

它应该传递允许用户访问某些菜单的值


湖上湖
浏览 131回答 1
1回答

慕标琳琳

<script>&nbsp; &nbsp; $('.form-check-input').on('click', function() {&nbsp; &nbsp; &nbsp; &nbsp; const menuId = $(this).data('menu');&nbsp; &nbsp; &nbsp; &nbsp; const roleId = $(this).data('role'); // roleId = <? $role[‘id’] ?> so php did not echo role id here&nbsp; &nbsp; &nbsp; &nbsp; $.ajax({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url: "<?= base_url('admin/changeaccess'); ?>",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: 'post',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data: {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; menuId: menuId,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; roleId: roleId&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success: function() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.location.href = "<?= base_url('admin/roleaccess/'); ?>" + roleId;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; });</script>对于解决方案,请更改您的form-check-input元素<... class=“form-check-input” data-role=“<?php echo $role[‘id’]; ?>” data-menu=“echo menu variable” ...>如果这样无法共享form-check-input按钮的html
打开App,查看更多内容
随时随地看视频慕课网APP