在输入字段中显示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>
JS:
<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从控制器获取值,有人能帮我返回Multiples值并将这些值显示在文本中吗
希望这能帮助
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
var obj= jQuery.parseJSON(response);
$('#admission').val(obj.admissionfee);
$('#tution').text(obj.tutionfee);
$('#exam').text(obj.examfee);
}else{
$('#admission').text('');
$('#tution').text('');
$('#exam').text('');
}
}
});