(h.datatype || “*”).tolowercase is not a function
前端表单通过POST请求发送数据
// 监听表单提交事件
form.on("submit(ShangChuan)",function (data) {
var param=data.field;
console.log(param);
// console.log(JSON.stringify(param));
$.post(url,param,"application/json; charset=utf-8",function(result){
if(result.success){
layer.alert(result.message,{icon:1});
//关闭窗口
layer.close(mainIndex);
tableIns.reload();
}else{
//刷新数据表格
layer.alert(result.message,{icon:2});
}
});
return false;
});
在后端controller 查不到数据
@RequestMapping(value = "/addJJFY_YL",method = RequestMethod.POST, produces ={"application/json;charset=UTF-8"})
public String addJJFY_YL(@RequestBody JJFY_YL jjfy_yl){
System.out.println(jjfy_yl);
logger.debug("添加数据:" + jjfy_yl);
Map<String,Object> map = new HashMap<String,Object>();
if(jjfy_ylService.addJJFY_YL(jjfy_yl)>0){
map.put("success",true);
map.put("message","添加成功");
}else{
map.put("success",false);
map.put("message","添加失败");
}
return JSON.toJSONString(map);
}
后来在网上找了好久,也试了很多方法,都不行,因为很少有人碰到这个问题,(h.datatype || “*”).tolowercase is not a function
后来看了一篇文章,试了试有效,发给大家,其实是个很简单问题。弄了我好久才解决:
就是把前端传值这边改一下:
$.post(url,param,"application/json; charset=utf-8",function(result)
改成:
$.post(url,param,'json',"application/json; charset=utf-8",function(result){
添加了小写的’json’
注意加引号’’
还有大家尽量少用这种写法,问题真多
$.post(url,param,'json',"application/json; charset=utf-8",function(result){
尽量写成这种的:
$.ajax({
url:url,
type:'POST',
contentType: "application/json; charset=utf-8",
dataType:'json',//json 返回值类型
data: JSON.stringify(param),//转化为json字符串
success:function(result){
if(result.success){
layer.alert(result.message,{icon:1});
//关闭窗口
layer.close(mainIndex);
tableIns.reload();
}else{
//刷新数据表格
layer.alert(result.message,{icon:2});
}
}
});
一目了然,还容易找问题,我大部分时间都在修改上面的简写方法,问题是真多呀,还不报错,只有启动服务才能找错,真的心累。