我想知道为什么在表单中通过 ajax 加载的表单元素没有发布(序列化)。这是我的代码:
<a href="javascript:;" data-toggle="modal" data-target="#editModal" onclick="load_credits_data('<?php echo $s['st_id'];?>','curriculum/home/get_student_memo','<?php echo $theYear;?>','<?php echo $theSeason;?>','<?php echo $s['semester_id'];?>','memo')" class="btn btn-xs green">
<i class="fa fa-edit"></i>
</a>
模态内的表格:
<div id="editModal" class="modal fade" tabindex="-1" data-width="400">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true"></button>
<h4 class="modal-title">ملا حظات</h4>
</div>
<form method="post" class="form-horizontal" id="srs_memoFormID">
<input type="hidden" name="test" id="test" value="2356789">
<div id="memo">
</div>
</form>
在表单中加载的部分视图:
<div class="modal-body" style="padding: 20px 30px;">
<div class="row">
<div class="col-sm-12">
<input type="hidden" name="student_srs_id" id="student_srs_id" value="<?php echo $srs_id; ?>">
<label class="control-label">ملا حظات</label>
<textarea name="srs_memo" id="srs_memo" form="srs_memoFormID" class="form-control">
<?php echo $memo; ?>
</textarea>
</div>
</div>
</div>
<div class="modal-footer" style="padding: 0px 30px 30px;">
<button type="button" data-dismiss="modal" class="btn btn-default">بستن</button>
<button type="button" class="btn btn-success" onclick="update_st_memo('curriculum/home/update_memo','srs_memoFormID','memo')">ذخیره کردن </button>
</div>
Ajax代码:
function update_st_memo(target_controller, formID, target_tag) {
$('#' + target_tag).css('height', 'auto').html('<img style="position: relative;top:40%;right:45%;" src="' + base_url + 'assets/css/loading-spinner-blue.gif"/>');
// alert($('#test').val())
$.ajax({
url: base_url + target_controller,
type: 'POST',
// data: {srs_id: $('#srs_id').val(),memo: $('#memo').val()},
data: $('#' + formID).serialize(),
success: function (result)
{
console.log(result)
},
})
}
答案 0 :(得分:0)
Html表格:
<form method="post" class="form-horizontal" id="srs_memoFormID">
<input type="hidden" name="test" id="test" value="2356789">
<div id="memo">
</div>
</form>
在你的剧本中:
data: $('#srs_memoFormID').serialize(),
(OR)
data: $('#srs_'formID).serialize(),
(OR)
var dataString = $('#srs_memoFormID').serialize();