'Access-Control-Allow-Origin'에 해당되는 글 1건

  1. 2013.04.23 [jQuery] XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin

[jQuery] XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin

jQuery로 서버에 ajax 요청할 경우 종종 보게 되는 Origin 문제

해결

1. 서버 - 헤더 정보를 셋팅하고 ResponseEntity 객체 리턴

@GET
@Path("/getUsers")
@Produces(MediaType.APPLICATION_JSON)
public ResponseEntity getUsers(@QueryParam("callback") String callback) {
    Set<User> list = null;
    list = userBo.getUsers();
    HttpHeaders headers = new HttpHeaders();
    headers.add("Access-Control-Allow-Origin", "*");
    headers.add("Access-Control-Allow-Methods", "GET, OPTIONS, POST");
    headers.add("Access-Control-Allow-Headers", "Content-Type");
return new ResponseEntity(list.toString(), headers, HttpStatus.OK);
}


2. 클라이언트 - chrome 인 경우 : 임시적 방법

(링크에 --disable-web-security 옵션 추가)


참고 : http://stackoverflow.com/questions/10718030/change-header-of-java-web-service-response-without-having-jackson-convert-it


'javascript' 카테고리의 다른 글

[jQuery] :input 선택자 (폼 태그 내 모든 입력 관련 선택)  (0) 2013.05.10
[jQuery] ajax prototype  (0) 2013.04.17
Posted by airlueos
,