Program/javascript

CORS (Cross Domain) ajax 우회하기

soccerda 2020. 10. 22. 17:43
반응형

cors 문제를 우회하기 위해서

jquery.ajaxPrefilter() 를 사용한다.

ajax에는 json으로 설정해두고 통신할때 prefilter에서 jsonp로 속여서 보내는 방식으로 아래와 같이 사용하면 된다.

 

	    $.ajaxPrefilter('json', function(options, orig, jqXHR) {
            return 'jsonp';
        });
		$.ajax({
				url: "domain",
				crossDomain: true,
				dataType: "json",
				method: "GET",
				data: {},
				headers: {                    
                },
				success: function(result, textStatus, jqXHR ) {					
				}
		});

 

반응형