본문 바로가기

뇌/Web

[Spring] Interceptor에서 Ajax요청 구분하기

# request Header의 'X-Requested-With'가 'XMLHttpRequest'인지 확인한다.

if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))) {

...

}


참고로 X-Requested-With의 접두사 'X'는 표준이 아니지만, jQuery등 대중성 있는 라이브러리들이

이 헤더를 Ajax시 추가하여 전송하고 있다고 한다.

참조 : http://mohwaproject.tistory.com/entry/Ajax-%EC%A0%84%EC%86%A1-%EA%B5%AC%EB%B6%84%ED%95%98%EA%B8%B0