如何接受来自Ajax调用控制器串retrun [英] how to accept string retrun from controller in ajax call
问题描述
我有一个jsp页面中说,像这样
I have a jsp page say something like this
<div id="result">
Connection not Enabled
<br>
<br>
<button id="enableconnection">Click to Enable connection
</button></div>
一旦我们连接上点击未启用按钮,它会做一些处理,最后它调用一个js函数是这样的:
once we click on connection not Enabled button it will do some process and at last it invoke a js function like this:
$.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调用成功阻止此字符串值?
Now respose is going into error block of js function not in success how to get this string value in success block of ajax call ?
推荐答案
网址:的contextPath +/ submitAllInfo,
此URL不与下面的动作相匹配。
url:contextPath +"/submitAllInfo",
this url is not matching with below action
@RequestMapping(值=/动作,方法= RequestMethod.POST)
,你也传递数据
从 Ajax请求
但并没有什么处理的控制器方法
字符串insertAllStepDetails()
应该是这样
and also you passing data
from your ajax request
but there is nothing to handle in controller method
String insertAllStepDetails()
it should be like
-
字符串insertAllStepDetails(@ModelAttribute(FORMDATA)AnyClass OBJ)
或 -
字符串insertAllStepDetails(HttpServletRequest的要求)
String insertAllStepDetails(@ModelAttribute("formData") AnyClass obj)
orString insertAllStepDetails(HttpServletRequest request)
和还删除过程数据:假的,
从 Ajax请求
这篇关于如何接受来自Ajax调用控制器串retrun的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!