ajax 및 window.close기능에 대해 질문드립니다.
$('.boardlist').click(function(){
alert("name");
var comSubmit = new ComSubmit('registerboard').serialize();
$.ajax({
type: "POST",
url: '<c:url value='/custompage/customwrite'/>',
data: comSubmit,
success: function(res){
if (res) {
window.close();
//opener.parent.location.reload();
}
}, error: function (xhr, status, error){
alert("error 발생!!" + error);
}
});
});
-------
<form name="registerboard" class="registerboard" method="post" action="<c:url value='/custompage/customwrite'/>" style="float:left" >
window.open으로 연 창(팝업창)에서 값을 입력하고, 그걸 제출 후 controller를 통해 db저장, 창을 닫은 후, 열었던 페이지를 새로고침하려고 합니다.
위는 subject 버튼 누를 시 그걸 ajax로 돌려본 거랑, jsp페이지 상의 form 제출 주소를 넣은 것입니다.
@ResponseBody
@RequestMapping("/customwrite")
public boolean boardRegister(@ModelAttribute customVO vo,
HttpSession session,
@RequestParam("bdname") String bdname,
@RequestParam("b2") String subcode,
@RequestParam("c") String category
)
{
vo.setBdname(bdname);
vo.setUsage('Y');
vo.setOpensubcode(subcode);
int categorycode=Integer.parseInt(service.categorycode(category));
vo.setCategorycode(categorycode);
boolean bool=true;
String usertype= (String)session.getAttribute("usertype");
if (usertype.equals("professor")) {
vo.setAuthcode(4);
}else if(usertype.equals("admin")) {
String code= (String)session.getAttribute("no");
String authcode= service.adminfound(code);
vo.setAuthcode(Integer.parseInt(authcode));
}
int result=service.insertboard(vo);
logger.info("처리중, vo={}, result={}",vo,result);
if (result!=1) {
bool=false;
}
return bool;
}
--컨트롤러.
문제는.... 여기부터입니다..
controller에 값은 잘가고, db등록도 확인했습니다.
그런데 생각한대로 창이 닫히지 않고 window.open으로 열었던 팝업창이 위와 같이 변경됩니다
(출력된 것은 return시킨 값).
주소란에는 보낸 controller 주소값이 나와있고요.
아직 초보라 해결방법을 모르겠습니다.
어떻게 코드를 바꿔야 제가 노렸던 결과를 얻을 수 있을까요?
$('.boardlist')가 클릭되지 않고 단순히 form이 submit으로 제출된 것 같습니다.
$('.boardlist')를 클릭하여 ajax 호출이 정상적으로 되었는지 확인할 필요가 있을 것 같습니다.
alert('name')이 호출되지 않는다면 $('.boardlist') 클릭이 호출되지 않은 것으로 보면 될 것 같습니다.