codeigniter javascript で post アクションを実行した後、チェックボックスが false の値を返します。
関数 subjectid_change のコードは次のとおりです。
function subjectid_change(id, subjectid){
setValue(id, subjectid);
var field = '#ch' + id;
set_credithour(field, subjectid);
}
$("select[name^=subjectid]").change(function(){
var subjectid = $(this).val();
set_credithour($(this).parent('td').find('input'), subjectid);
$(this).parent().find('input').attr('name', 'credithour['+subjectid+']');
$(this).parent().next()find('input').attr('name', 'gradepoint['+subjectid+']');
$(this).parent().next().next().find('input').attr('name', 'cgpacalc['+subjectid+']');
});
試してみe.preventDefault();
ましたが、以前の値を変更できませんでした。私も使用.prop("checked")
してみましたが、結果は同じです。
subjectid_change 関数のこのコード:
function set_credithour(field, subjectid){
$.post('<?php echo site_url('academic/ajax_get_subject_credit'); ?>', {subjectid:subjectid},
function(response){
if(response.success){
$(field).val(response.value);
} else{
alert('The subject you entered has no credit hour.');
}
}, 'json');
}
では、実行後にチェックボックスをオンにしたままにしたい場合はどうすればよいですか$.post
。
コントローラーで:
function ajax_get_subject_credit()
{
$subjectid = $this->input->post('subjectid');
$this->db->select('subjectid, subjectcredit');
$this->db->where('subjectid',$subjectid);
$query = $this->db->get('ref_subject');
$credithour = $query->row()->subjectcredit;
$query->free_result();
$result = $credithour;
echo json_encode(array('success' => true, 'value' => $result));
}
科目を選択すると、クレジット時間が自動入力され、チェックボックスをクリックして CGPA の計算に同意します。しかし、新しいサブジェクトを追加した後に [計算] ボタンをクリックすると、計算プロセスが実行されず、チェックボックスが false に戻ります。そのため、プロセスを機能させるには、チェックボックスをもう一度クリックして [計算] ボタンをクリックする必要があります。これにより、ユーザーは同じジョブを 2 回実行します。この問題を解決するには?