gpt4 book ai didi

java - 无法使用ajax调用spring Controller

转载 作者:行者123 更新时间:2023-12-01 02:10:59 24 4
gpt4 key购买 nike

我正在尝试使用ajax调用spring Controller ,但无法访问该 Controller 。我收到错误 405 请求方法“POST”不支持的错误。我将我的代码保留在这里,请提出建议来解决它

这是我从jsp页面调用 Controller 的ajax代码,在这里我获取了 anchor 属性值。

基本.jsp

function organizationData(anchor) {
var value = anchor.getAttribute('value');
$.ajax({
url : "manageOrganization",
method : "GET",
dataType: "json",
contentType: 'application/json',
data: {organizationId : value },
success : function(response) {
alert(response);
},
error : function(e) {
alert('Error: ' + e);
}
});
}

Controller

@RequestMapping(value="/manageOrganization", method = RequestMethod.GET)
public String organizationData(@RequestParam String organizationId) {
return organizationId+" associated";
}

这里我应该将字符串作为 ajax 响应获取到 jsp,但我收到了错误消息。任何人都可以帮助我。

问候斯雷

最佳答案

对于 json 响应,您需要向 Controller 方法添加 @ResponseBody 注释。

关于java - 无法使用ajax调用spring Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22854419/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com