我有一个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/