我有一个Java脚本AJAX方法,该方法将参数发送到控制器
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);
}
});
}
但是,当我在控制器中使用print_r尝试时,它会显示(Day12)两个ID的一天都可以将数据传递给控制器的方式正确?
尝试以下:
$.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控制器中,您可以使用$ _POST获得这些值。(print_r($ _ post))数组。
您还应该尝试像Ajax Call
一样发送数据var frm_data = {day: day,section_id:section_id,class_id:class_id}
$.ajax({
url: '<?php echo base_url(); ?>index.php?admin/get_class_section/',
type: 'POST',
data: frm_data,
dataType:'JSON',
success: function(response)
{
jQuery('#section_selection_holder').html(response);
}
});
使用以下代码使用参数调用ajax
function class_selection(day) {
var section_id = document.getElementById('section_id2').value;
var class_id = document.getElementById('class_id').value;
$.ajax({
type: "POST",
dataType: 'json',
data: 'day=' + day + '§ionId=' section_id + '&classId=' + class_id,
url: 'index.php?admin/get_class_section',
success: function(json) {
//your response here
}
});
}