(h.datatype || “*“).tolowercase is not a function

(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});
                        }
                    }
                });

一目了然,还容易找问题,我大部分时间都在修改上面的简写方法,问题是真多呀,还不报错,只有启动服务才能找错,真的心累。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值