我想将控制器方法的返回值(即标志)发送到我的视图中,并且在视图中我需要根据此标志显示一条警报消息。这是我的控制器代码
@RequestMapping(value = "/testing", method = RequestMethod.POST)
public Boolean testing(@RequestBody String value, HttpSession session, String username, ModelMap modelMap, HttpServletRequest request) throws Exception {
Boolean flag = false;
User userData = (User) session.getAttribute("MEMBER");
for (OrgData org: orgDataRepository.findAll()) {
if (m.getValue() != null) {
sourceAccessToken = (String) m.getValue();
flag = true;
} else {
System.out.println("Refresh token is expired");
flag = false;
}
}
return flag;
}
我的视图代码如下所示
let btnVal = document.querySelectorAll('.test-btn');
for (let i = 0; i < btnVal.length; i++) {
let btns = btnVal[i];
btns.onclick = function() {
var selchbox = getSelectedChbox(this.form); // gets the array returned by getSelectedChbox()
if (selchbox.length == 1) {
//document.write("check check"+selchbox);
$.ajax({
type: "POST",
url: "/testing",
dataType: "JSON",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(selchbox),
cache: false,
success: function(data) {
alert("SUCCESS!!!");
},
error: function(args) {
/* alert("Error on ajax post");
console.log("Error"+args); */
}
});
} else {
alert("Please select only one check box");
}
}
}
我想在这个 ajax 调用中发送那个布尔值并显示一个弹出窗口或警报框。如何实现这一目标?
眼眸繁星
炎炎设计
largeQ
相关分类