【发布时间】:2015-06-03 17:06:58
【问题描述】:
我正在尝试发布 jquery Ajax 请求,但它没有发送到我的 MVC 控制器。
$.ajax({
url : contextPath + "/check/panelnumber",
type : "POST",
contentType : "application/json",
data :{
"execution" : execution,
"panelNumber" : panelNumber
},
});
Spring MVC 控制器
@Controller
@RequestMapping("/check")
public class ValidateFieldValueController extends FlowEnabledBaseController {
@RequestMapping(value = "/panelnumber", method = RequestMethod.POST)
public ResponseEntity<String> checkPanelNumber(HttpServletRequest request,
HttpServletResponse response,
@RequestParam("panelNumber") String panelNumber,
@RequestParam("execution") String execution) {
......
Gson gson = new Gson();
return new ResponseEntity<String>(gson.toJson(details), HttpStatus.OK);
}
但是它对于 GET 方法非常有效! 尝试添加 dataType: "json" ,但即使 GET 调用也停止工作。浏览器控制台显示错误为 HTTP 400 错误请求,但通过 firefox 插件检查时,POST 参数正常。 有什么帮助吗?
【问题讨论】:
-
$.ajax调用的匹配右括号在哪里? -
这是错字...已更正问题
-
您似乎并没有真正发送 JSON,因此将 contentType 设置为 appliation/json 没有意义。
标签: javascript jquery ajax spring-mvc