我有一个按钮可以执行对我的服务器的POST请求,但它不起作用。
我的应用程序禁用了csfr,并且我还有其他使用$.post()的按钮,它工作得很好。在讨论的函数中,它永远不会到达服务器端。
这是按钮:
<button onclick="honor('gold', '${loggedUser.username}')" style="margin-right: 2%;"
class="btn btn-info pull-right">
<span style="padding: 2em 4em;">NEXT</span>
</button>这是荣誉函数:
function honor(type, username) {
var message = $("#message").val();
var name = $("#honor-box").attr("name");
var id = name.substring(1);
$.ajax({
type : "POST",
url : "http://(emitted)/honor?type=" + type + "&id="
+ id + "&name=" + username,
data : message,
dataType : "json"
});
}服务器端函数头:
@RequestMapping(value = "/honor", method = RequestMethod.POST)
public void giveHonor(Principal principal, Model model, @RequestParam(name = "type") String type,
@RequestParam(name = "id") String id, @RequestParam(name = "name") String name,
@RequestParam("json") String message)当我从honor()中删除data: message,并从giveHonor()中删除@RequestParam("json") String message时,它就起作用了,所以问题确实存在。
我需要荣誉()函数将信息发送到服务器端的giveHonor()。
发布于 2019-01-24 00:04:35
您收到了作为参数的消息。将其作为参数从ajax传递。
$.ajax({
type : "POST",
url : "http://(emitted)/honor?type=" + type + "&id="
+ id + "&name=" + username + "&json="+ message,
});https://stackoverflow.com/questions/54330164
复制相似问题