这是我正在从事的CRUD项目,对此我还很陌生。我有一个DataTable,它仅显示数据库中的特定表。
例如,我不能使用SELECT语句从数据库中获取“主题”或“描述”表,但可以在一个例外情况下使用“标题”,“作者”等,必须将查询调整为限制为200行; "SELECT * FROM members LIMIT 200"
如果不是这种情况,则会出现此错误:
DataTables警告:表id = manageMemberTable-无效的JSON响应。有关此错误的更多信息,请参见http://datatables.net/tn/1
我的数据表无法加载。
此外,当我要编辑一行数据时,HTML输入不会自动填充数据。我一直在研究它,并尝试解决了几个小时,我在开发人员工具>网络中发现的只是具有所需数据的阵列...
我的JS提取数据:
$.ajax({
url: 'php_action/getSelectedMember.php',
type: 'post',
data: {member_id : id},
dataType: 'json',
success:function(response) {
$("#editTitle").val(response.title);
$("#editAuthor").val(response.author);
$("#editPaginas").val(response.paginas);
...
显示数据的HTML:
<!-- edit modal -->
<div class="modal fade" tabindex="-1" role="dialog" id="editMemberModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title"><span class="fa fa-edit"></span> Edit Member</h4>
</div>
<form class="form-horizontal" action="php_action/update.php" method="POST" id="updateMemberForm">
<div class="modal-body">
<div class="edit-messages"></div>
<div class="form-group">
<!--addclass has-error komt hier -->
<label for="editTitle" class="col-sm-2 control-label">Title</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="editTitle" name="editTitle" placeholder="Title">
<!-- text komt hier -->
</div>
</div>
<div class="form-group">
<label for="editAuthor" class="col-sm-2 control-label">Author</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="editAuthor" name="editAuthor" placeholder="Author">
</div>
</div>
<div class="form-group">
<label for="editPaginas" class="col-sm-2 control-label">Paginas</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="editPaginas" name="editPaginas" placeholder="Paginas">
</div>
</div>
</div>
<div class="modal-footer editMemberModal">
<button type="button" class="btn btn-default" data- dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save changes</button>
</div>
</form>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- /edit modal -->