1:部分代码 :
```php
table.render({
elem: '#munu-table'
, url: '/WarehousingRecord/pending_inventory'
,id:"table"
,page:{
limit: 15
, limits: [15, 20, 30, 40, 50, 100, 150, 200, 250, 300, 400, 500, 800, 1000]
// ,curr:localStorage.getItem('spgl_curr') ? localStorage.getItem('spgl_curr') : 1
}
,totalRow: true //开启合计行
, cols: [[
{type: 'checkbox', width: 40, sort: true},
{field: 'id', width: 140, title: 'id',hide:true},
{field: 'image', width: 70, title: '图片',templet:function (d) {
return '';
}},
{field: 'list_number', width: 100, title: '清单编号'},
{field: 'storage_id', width: 100, title: '入库编号'},
{field: 'batch_number', width: 80, title: '批次号'},
{field: 'sku', width: 80, title: 'sku'},
{field: 'storage_quantity', width: 90, title: '入库数量'},
{field: 'sample_quantity', width: 90, title: '留样数量'},
{field: 'actual_packing_quantity', width: 115, title: '实际装箱数量'},
{field: 'purchaser', width: 80, title: '采购人'},
{field: 'outbound_date', width: 100, title: '出库日期'},
{field: 'pending_days', width: 100, title: '待处理天数'},
{field: 'processing_status', width: 100, title: '处理进度'},
{field: 'processor', width: 80, title: '处理人'},
{field: 'processing_method', width: 100, title: '处理方式'},
{field: 'created_time', width: 100, title: '创建时间'},
{field: 'modified_time', width: 100, title: '修改时间'},
]]
2:检查上面的接口是否正常 :
, url: '/WarehousingRecord/pending_inventory' (根据自身情况来写 也可以写绝对地址 https:xxx.com/example/index)
后端代码 PHP例子:
public function pending_inventory() {
}
注意:此时接口 如果报错 数据接口请求异常:error 说明接口 已经通了
我的情况是不管 写不写代码都会报错:数据接口请求异常:parsererror 然后将接口换成同事的接口能够展示表格数据 。 将同事的表格 的代码全部注释后 报错:数据接口请求异常:error
到这时我才发现 我的错误根本不是代码错误 而是接口都没有 走通 。 询问 组长 在CakePHP 中
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('update_product_error_module_en','async_price',"counts","addInventoryRecordapi",'warehouses_api',"to_examine","create_batch",'pvn_sel','tariff_list','addOutInventoryRecord','aaa','addWarehousingAPI',"batch_consolidation","upd_wr_invoice","batch_invoice_api","upd_fp","ces","upd_wr_sku","collectMinin","collectMinin_data","upd_s_p_d","split_batches","update_price",'Generate_Warehouse_Receipts','Add_Number_1','Generate_Warehouse_Receipts1',"portfolio_product_warehousing","splitting_products","composite_product_creation_batch","product_information","order_information","upd_hk_waybill",'confirm_inventory','update_batch','cancel_pending_stock','upd_rk_time','get_price','check_outbound_batch','add_outbound_record','pending_inventory','pending_inventory_data');
} 将自己要请求的控制器 放到 里面 才走通 。
一般来说 数据接口请求异常:error 说明接口已经走通了 , 错误可能子sql 写错,代码 错误
数据接口请求异常:parsererror 一般来说 是请求网络的错误 比如说服务器返回400 500 等 。
关于后端返回的数据格式问题:(PHP)
$a = array(
"code" => 0,
"msg" => "查询数据完成",
'count' => 1000,
'data' => array(
array('id' => 1, 'purchaser' => 'mark', 'storage_id' => 25),
array('id' => 2, 'purchaser' => 'Jane', 'storage_id' => 30),
array('id' => 3, 'purchaser' => 'Jane', 'storage_id' => 30),
array('id' => 4, 'purchaser' => 'Jane', 'storage_id' => 30),
array('id' => 5, 'purchaser' => 'Jane', 'storage_id' => 30),
array('id' => 6, 'purchaser' => 'Jane', 'storage_id' => 30),
)
code 必须是0
msg 一般不为空
$data 的数据格式 可以像我这样 写点数据 来测试 打印 然后将查询的数据根据测试的数据来修改 即可 。