Struts2 기반에서 Ajax를 사용해 Json으로 결과값을 받을 때,

같은 메소드가 두 번 호출된다거나, 호출하지 않은 메소드도 막 돌 때가 있다.

이거 참 골치아픈 문제였는데 외국의 어느 형님이 명쾌하게 답변을 내려주셨다.




찬양하여라!!


요는 Json 플러그인은 Action에 get으로 시작하는 메소드를 모조리 읽을 수 있으니 이름 바까라.



출처 : https://stackoverflow.com/questions/6061709/struts2-action-being-called-twice-if-result-type-is-json?answertab=votes#tab-top


Posted by 좀모씨


var xmlHttp;

function srvTime() {

if (window.XMLHttpRequest) {// 분기하지 않으면 IE에서만 작동된다.

xmlHttp = new XMLHttpRequest(); // IE 7.0 이상, 크롬, 파이어폭스 등

xmlHttp.open('HEAD', window.location.href.toString(), false);

xmlHttp.setRequestHeader("Content-Type", "text/html");

xmlHttp.send('');

return xmlHttp.getResponseHeader("Date");

} else if (window.ActiveXObject) {

xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');

xmlHttp.open('HEAD', window.location.href.toString(), false);

xmlHttp.setRequestHeader("Content-Type", "text/html");

xmlHttp.send('');

return xmlHttp.getResponseHeader("Date");

}

}

var st = srvTime();

var date = new Date(st);

var today = date.getFullYear() + addZero(date.getMonth() + 1)

+ addZero(date.getDate());


function addZero(n) {

return n < 10 ? "0" + n : n;

}





Posted by 좀모씨

블로그 이미지
Under Construction
좀모씨
Yesterday
Today
Total

달력

 « |  » 2024.4
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함