Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ajax在codeigniter中获得多个值_Javascript_Php_Jquery_Codeigniter - Fatal编程技术网

Javascript Ajax在codeigniter中获得多个值

Javascript Ajax在codeigniter中获得多个值,javascript,php,jquery,codeigniter,Javascript,Php,Jquery,Codeigniter,将ajax响应显示到输入字段中,但它不起作用 HTML代码: <html> <select name="class_id" class="form-control" data-validate="required" id="class_id" data-message-required="<?php echo get_phrase('value_required');?>" onchange="return et_student_fees(this.value)

将ajax响应显示到输入字段中,但它不起作用

HTML代码:

<html>
<select name="class_id" class="form-control" data-validate="required" id="class_id" 
data-message-required="<?php echo get_phrase('value_required');?>" 
onchange="return et_student_fees(this.value)">                 
<div class="form-group">
<input id="admission" value=""  type="text" class="form-control" name="admission-fee" >                     
<input id="tuition" type="text" class="form-control" name="tuition-fee" value="">                       
<input id="exam" type="text" class="form-control" name="exam-fee" value=""></div>
</html>
<script type="text/JavaScript">

function get_student_fees(class_id)
{

    $.ajax({
        url: '<?php echo base_url();?>index.php?admin/get_student_fees/' + class_id ,
        success: function(response)
        {                           
                var len = response.length;

            if(len > 0){
            // Read values
            $('#admission').val(response.admissionfee);
            $('#tution').text(response.tutionfee);
            $('#exam').text(response.examfee);

            }else{
            $('#admission').text('');
            $('#tution').text('');
            $('#exam').text('');
            }
        }
    });
function get_student_fees($class_id)
{
    $fees = $this->db->get_where('fees' , array('class_id' => $class_id
    ))->result_array();

    foreach ($fees as $row) {
    $response = array();
    $data['admissionfee'] = $row['admissionfee'];
    $data['tutionfee'] = $row['tutionfee'];
    $data['examfee'] = $row['examfee'];
    array_push($response , $data);
    }
   echo json_encode($response);

   }
使用ajax从控制器获取值,有人能帮我返回多个值并将这些值显示为文本字段吗

希望这有帮助

函数获取学生费用(班级id){
$.ajax({
url:'index.php?admin/get_student_fees/'+class_id,
成功:功能(响应){
var len=响应长度;
如果(len>0){
//读取值
var obj=jQuery.parseJSON(响应);
$('入院').val(客观入院费);
$(#tution').text(obj.tutionfee);
$('考试').text(obj.examfee);
}否则{
$(“#录取”)。文本(“”);
$('#tution')。文本('');
$(“#考试”)。文本(“”);
}
}

})
您的输入id是
学费
,您在ajax代码中拼错了它,即:
#学费
,相应地更改它。另外,检查
响应
中有什么。更改后,response.admissionfee没有定义,但是response有所有值。您是否可以在此时检查回调函数名
change=“return et\u student\u fees(this.value)
因为您的函数名是
get\u student\u fees()
,但您将其称为
et\u student\u fees()
已更正,但仍然存在相同的问题。请欣赏这一点,但这项技术并不能解决问题。请提供更多建议。