我已经在JavaScript中创建了一个表单并将其显示在元素中。但是当我必须以该表格提交时,它是行不通的。
这是我的代码:
// This is my javascript for submit.
$('#EncodeGradesForm').submit(function() {
$.ajax({
url: '<?php echo base_url('
grade / encode ') ?>',
type: 'POST',
data: $(this).serialize(),
success: function() {
alert('Submitted!');
}
});
});
var encoding;
encoding = '<div class="alert alert-info">Encoding Grades...</div>';
encoding = '<form id="EncodeGradesForm">';
encoding += '<input type="hidden" name="subject_id" value="<?php echo $subjectData['id'] ?>">';
encoding += '<input type="hidden" name="section_id" value="<?php echo $section_id ?>">';
encoding += '<input type="hidden" name="grading_id" value="' + grades_id + '">';
encoding += '<input type="hidden" name="grade_id" value="' + content_id + '">';
encoding += '<table class="table table-bordered table-border">';
encoding += '<thead>';
encoding += '<tr>';
encoding += '<td class="text-center">Student</td>';
encoding += '<td class="text-center">Grade</td>';
encoding += '</tr>';
encoding += '</thead>';
encoding += '<tbody>';
for (var i = 0; i < data.length; i++) {
encoding += '<tr>' +
'<td width="90%" class="text-center">' + data[i].firstname + ' ' + data[i].lastname + '</td>' +
'<td width="10%" class="text-center"><input type="hidden" name="student[]" value="' + data[i].id + '" /><input type="number" name="score[' + data[i].id + ']" class="form-control" style="width: 100px; margib: auto;" /></td>' +
'</tr>';
}
encoding += '</tbody>';
encoding += '</table>';
encoding += '<button type="submit" class="btn btn-primary btn-block">Submit Grade/s</button>';
encoding += '</form>';
$('#collapseContent' + content_id).html(encoding);