【发布时间】:2019-06-27 01:01:37
【问题描述】:
我在 codeigniter 中向我的模型写入查询,当被 ajax 访问时它返回错误 HTTP 500,但是当使用浏览器时它没有 HTTP 错误代码:
$query = 'select album.id,
album.name,
artist.name as artist,
artist.name as artistid,
album.photo,
album.active,
album.reasonactive from ' . $this->table .
' join artist on artist.id = album.ref_artist ';
if(isset($_POST["search"]["value"])){
$query .= '(artist.name LIKE "%'.$_POST["search"]["value"].'%" ';
$query .= 'OR album.name LIKE "%'.$_POST["search"]["value"].'%" ';
}
if(isset($_POST["order"])){
$query .= 'ORDER BY '.$column[$_POST['order']['0']['column']].' '.$_POST['order']['0']['dir'].' ';
}
else
{
$query .= ' ORDER BY album.name asc ';
}
if($_POST['length'] != -1)
$query .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
$result = $this->db->query($query);
return $result->result();
这是我的 ajax 代码:
$(document).ready(function() {
table = $('#table').DataTable({
"processing": true, //Feature control the processing indicator.
"serverSide": true, //Feature control DataTables' server-side processing mode.
"order": [], //Initial no order.
// Load data for the table's content from an Ajax source
"ajax": {
"url": "<?php echo base_url('Manage/get_all')?>",
"type": "POST"
},
//Set column definition initialisation properties.
"columnDefs": [
{
"targets": [ 0 ], //first column
"orderable": false, //set not orderable
},
{
"targets": [ -1 ], //last column
"orderable": false, //set not orderable
},
],
});
但是当我更改并删除过滤器查询时:
$query = 'select album.id,
album.name,
artist.name as artist,
artist.name as artistid,
album.photo,
album.active,
album.reasonactive from ' . $this->table . ' join artist on artist.id = album.ref_artist ';
代码运行成功。
在我的 codeigniter 消息中:
注意:未定义的索引:长度
注意:未定义索引:开始
注意:未定义索引:draw
当我显示 $_POST 时:
{"draw":null,"recordsTotal":2,"recordsFiltered":2,"data":[]}
我该如何解决这个问题?非常感谢您在此问题上的时间和帮助。
【问题讨论】:
-
日志文件有什么错误?
-
Failed to load resource: the server responded with a status of 500 (Internal Server Error)。只有这个节目在控制台先生 -
codeigniter 日志中有什么内容?
-
Undefined index: draw, start, lenght先生。 -
这是 2019 年的老兄 - 你真的不需要让自己暴露在如此简单的 sql 注入威胁中......
标签: javascript php jquery codeigniter datatables