javascript - 如何单独传递ajax调用参数

标签 javascript php ajax codeigniter

我有一个java脚本ajax方法,它将参数发送到 Controller

function class_selection(day) {

        var section_id = document.getElementById('section_id2').value;
        var class_id = document.getElementById('class_id').value;
       // alert("day"+day);
        alert("class_id"+class_id);
        alert("section_id"+section_id);

        $.ajax({
            url: '<?php echo base_url(); ?>index.php?admin/get_class_section/' + day + section_id +  class_id,
           // alert("url"+url);
            success: function(response)
            {
                jQuery('#section_selection_holder').html(response);
            }
        });
    }

但是当我尝试在 Controller 中使用 print_r 时,它显示(第 12 天) 当天都有两个 id,那么将数据传递到 Controller 的方式是否正确?

最佳答案

试试这个:

 $.ajax({
        url: '<?php echo base_url(); ?>index.php?admin/get_class_section/',
       data: {day: day, section_id: section_id, class_id: class_id},
       method: POST,
        success: function(response)
        {
            jQuery('#section_selection_holder').html(response);
        }
    });

并且在您的 php Controller 中您可以使用 $_POST 获取这些值。 (print_r($_POST)) 数组。

关于javascript - 如何单独传递ajax调用参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40838768/

相关文章:

php - CS Cart 4移动支付界面

php - 通过 AJAX 评估 PHP

javascript - foreach 数组的未定义结果 javascript

JavaScript/HTML : Changing an image border onclick

javascript - 汉堡响应式按钮点击事件BUG

javascript - 是否可以从javascript中的条件(三元)运算符获取两个值?

php - Docker 服务分离

php - 一个按钮工作,其他按钮出现错误 : "Notice: Undefined index: dbconfig.php on line 6"

命名空间ajax函数回调中另一个命名空间的javascript访问函数

javascript - 为什么绘制 POT 图像比 NPOT 图像更快?