gpt4 book ai didi

java - 带有spring mvc的ajax总是出错

转载 作者:搜寻专家 更新时间:2023-11-01 03:50:12 26 4
gpt4 key购买 nike

每个请求 ajax 都会出错。 Ajax 功能:

function doAjax() {
var inputText = $("#info").val();
$.ajax({
type: 'POST',
url: 'ajax',
// data: ({text: inputText}),
dataType: 'json',
data: 'text='+inputText,
success: function (response) {
$("#result_info").text(response);
}
error: function (e) {
alert('error' + e.responseText);
}
});
}

Java Controller

@RequestMapping(value = {"/ajax"}, method = RequestMethod.POST)
public @ResponseBody String showText(@RequestParam String text) {
System.out.println(text);
String returnText = "empty";
if (!text.isEmpty()) {
returnText = " response: " + text;
}

return returnText;
}

除了这个问题,你能说说 ajax 查询之间的区别吗

data: ({text: inputText}), 
data: 'text='+inputText,

最佳答案

在这种特殊情况下,最好将数据类型更改为 html 而不是 json。我解决了。

关于java - 带有spring mvc的ajax总是出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30728405/

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