我有一个jsp页面说出类似这样的内容
<div id="result">
Connection not Enabled
<br>
<br>
<button id="enableconnection">Click to Enable connection
</button></div>
一旦我们点击连接未启用按钮,它将执行一些过程,最后它会调用这样的js函数:
$.ajax({
url:contextPath +"/submitAllInfo",
type: 'POST',
data: formdata,
async: false,
processData: false,
contentType: false,
success: function (data) {
$("#result").html(data);
},
error: function (){
alert("error has cocured");
},
cache: false
});
控制器逻辑
@RequestMapping(value = "/action", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public @ResponseBody
String insertAllStepDetails(){
// some code
String t ="done";
return t;
}
现在respose正在进入js函数的错误块而不是成功如何在ajax调用的成功块中获取此字符串值?
答案 0 :(得分:0)
在您的成功功能中,您希望通过更改:
来显示此新调用的数据$("#result").html("connection has been enabled successfully");
要:
$("#result").text(data);
答案 1 :(得分:0)
url:contextPath +"/submitAllInfo",
此网址与以下操作不匹配
@RequestMapping(value = "/action", method = RequestMethod.POST)
并且您还从data
传递ajax request
,但controller method
String insertAllStepDetails()
无法处理
String insertAllStepDetails(@ModelAttribute("formData") AnyClass obj)
或String insertAllStepDetails(HttpServletRequest request)
并从processData: false,
ajax request