提问人:Uranus_ly 提问时间:10/10/2023 最后编辑:dan1stUranus_ly 更新时间:10/10/2023 访问量:22
ajax请求成功后如何执行控制器?
How to execute the controller when the ajax request is successed?
问:
我正在尝试在ajax请求成功时执行控制器api。我想在kakao api请求成功时执行,但会话对象是服务器对象,因此无法在jsp的脚本标签中使用。添加,loginOK api 中的对象不在 kakao api 中,但我只想在 jsp 中成功执行 kakao api reauest 时执行代码。如何修改守则?代码如下,这些代码位于 jsp 和控制器中,与登录功能相关。session.setAttribute("logStatus", "Y");
session.setAttribute("logStatus", "Y")
function kakaoLogin() {
Kakao.Auth.login({
success: function (response) {
// Kakao API
Kakao.API.request({
url: '/v2/user/me',
success: function (response) {
window.location.href = '/smhrd';
$.ajax({
// controller mapping
url: 'loginOk',
type: 'POST',
success: function (data) {
console.log(data);
// redirection
window.location.href = '/smhrd';
},
error: function (error) {
console.log(error);
},
});
},
fail: function (error) {
console.log(error);
},
});
},
fail: function (error) {
console.log(error);
},
});
}
@PostMapping("/loginOk")
public ModelAndView loginOk(String u_id, String u_pw, HttpSession session) {
UserDTO dto = service.loginOk(u_id, u_pw);
System.out.println("loginOk 호출성공");
ModelAndView mav = new ModelAndView();
if(dto != null) {
session.setAttribute("logId", dto.getU_id());
session.setAttribute("logName", dto.getU_name());
session.setAttribute("logStatus", "Y");
mav.setViewName("redirect:/");
}else {
mav.setViewName("register/loginResult");
}
return mav;
}
以下是调用函数 kakaoLogin() 时服务器中的错误 (5xx)。此外,当我检查结果时,直到代码“url:'/v2/user/me'”做得很好,但代码“console.log(data)”没有被调用,我认为控制器映射失败。
------the error(5xx)-----
[Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='param1', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=nul`
但是我不确定执行控制器“loginOk”是否正确,因为对象在 loginOk 中不在 kakaoAPI 中,因此调用控制器时没有 dto。
答: 暂无答案
评论