我尝试在使用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>
它应该传递允许用户访问某些菜单的值
答案 0 :(得分:0)
<script>
$('.form-check-input').on('click', function() {
const menuId = $(this).data('menu');
const roleId = $(this).data('role'); // roleId = <? $role[‘id’] ?> so php did not echo role id here
$.ajax({
url: "<?= base_url('admin/changeaccess'); ?>",
type: 'post',
data: {
menuId: menuId,
roleId: roleId
},
success: function() {
document.location.href = "<?= base_url('admin/roleaccess/'); ?>" + roleId;
}
});
});
</script>
要更改解决方案,请更改您的form-check-input
元素
<... class=“form-check-input” data-role=“<?php echo $role[‘id’]; ?>” data-menu=“echo menu variable” ...>
如果这无法共享您的form-check-input
按钮的html