蓝胧月 2020-05-30 14:58 采纳率: 50%
浏览 286
已采纳

springmvc使用ajax请求报错POST 415

chrome报错:POST http://localhost:8080/TCCZB_Server/wsd/wsdchangethreshold.do 415

我看了网上很多解答但都是添加contentType: "application/json;charset=UTF-8"或者是json序列化,但我添加后依旧报错415

jsp:

<input type="text" class="form-control user-input" name="text" id="temperature"
           placeholder="温度" data-pure-clear-button value="" autocomplete="off">
    <input type="text" class="form-control user-input" name="text" id="humidity"
           placeholder="温度" data-pure-clear-button value="" autocomplete="off">
    <button type="button" class="btn btn-primary" id="update_btn">修改</button>

js:

$(function () {
    console.log(appName);
    var func = {
        changethreshold: function () {
            var a = $("#temperature").val(), b = $("#humidity").val();
            var dataRow = {
                temperature: a,
                humidity: b
            };
            $.ajax({
                url: appName + "/wsd/wsdchangethreshold.do",
                type: "POST",
                data: JSON.stringify(dataRow),
                dataType: "json",
                contentType: "application/json;charset=UTF-8",
                success: function (result) {
                    $('#changethreshold').modal('hide');//隐藏模态框
                    if (result == "success") {
                        layer.msg("修改成功!", {icon: 1});
                    } else {
                        layer.msg("修改失败!", {icon: 5});
                    }
                }
            });
        }
    };

    $("#update_btn").on('click', function () {
        func.changethreshold();
    });

});

controller:

@Controller
@RequestMapping("/wsd")
public class WSDController {
    @Autowired
    private WSDService wsdService;

    @RequestMapping("/wsdchangethreshold.do")
    @ResponseBody
    public String changeThreshold(@RequestBody Threshold threshold) {
        if (wsdService.changeThreshold(threshold.getTemperature(),threshold.getHumidity()) == true) {
            return JSON.toJSONString("success");
        }
        return JSON.toJSONString("fail");
    }
}
  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 请问这个脚本bat清除tmp文件,会导致硬盘文件损坏吗?(操作系统-windows)
      • ¥15 IncredBuild报错
      • ¥15 锂电池偏最小二乘法参数辩识
      • ¥20 有偿求 matlab解GP方程程序
      • ¥15 session失效问题
      • ¥15 GMS地下水数值模拟无法打开
      • ¥15 树型结构的数据怎么匹配分支
      • ¥15 stm32F4用.引不出来结构体成员怎么解决
      • ¥30 Syntax Error: TypeError: this.getOptions is not a function的问题
      • ¥15 eclipse Android环境搭建