项目场景:

layui+php

用layui获取 table.cache[“你的lay-id”]; 时,得到的对象是object,如果直接放到 ajax的data post不了对象。后端接收也有错误。


问题描述:

layui的table.cache[lay-id],直接通过$.ajax的data:table.cache[lay-id],是无法上传正确的参数的。

$.ajax({
....
data:table.cache["你的lay-id"],
....
})

原因分析:

table.cache[“你的lay-id”]是object类型导致post并不完整

解决方案:

第一步:

var TbRows = table.cache["你的lay-id"];					
var str_TbRows = JSON.stringify(TbRows);
$.ajax({
....
data:{info:str_TbRows},
....
});

第三步:
后端php必须是:

$info=json_decode(html_entity_decode(urldecode($_POST["info"])), 1);

总结:

解决方法:
(1)obj需要转换成字符串 JSON.stringify(table.cache[lay-id])
(2)用ajax的data:{info:JSON.stringify(table.cache[lay-id])}
(3)后端接收需要转换成数组变量 json_decode(html_entity_decode(urldecode($_POST[“info”])), 1);

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐