2016-06-22 2 views

답변

0

CORS는 새 브라우저에서 지원하는 서버 측 기능입니다.

크로스 도메인 서비스에서 리소스를 요청하면 브라우저는 서버에 대한 프리 플라이트 요청을 수행하고 액세스 정보를 요청합니다.

서버가 다른 도메인의 리소스에 액세스 할 수있게하면 일부 HTTP 헤더를 다시 보내고 브라우저는 사용자의 작업에 대한 헤더를 결정합니다.

자세히 알아보기 here. 여기

0

는 당신이 그것을하는 방법이다이 제공 서버 측 구성이 완료 : 'URL을'로드 할 수 없습니다 http://www.html5rocks.com/en/tutorials/cors/

+0

XMLHttpRequest의 :

// Create the XHR object. function createCORSRequest(method, url) { var xhr = new XMLHttpRequest(); if ("withCredentials" in xhr) { // XHR for Chrome/Firefox/Opera/Safari. xhr.open(method, url, true); } else if (typeof XDomainRequest != "undefined") { // XDomainRequest for IE. xhr = new XDomainRequest(); xhr.open(method, url); } else { // CORS not supported. xhr = null; } return xhr; } // Helper method to parse the title tag from the response. function getTitle(text) { return text.match('<title>(.*)?</title>')[1]; } // Make the actual CORS request. function makeCorsRequest() { // All HTML5 Rocks properties support CORS. var url = 'http://updates.html5rocks.com'; var xhr = createCORSRequest('GET', url); if (!xhr) { alert('CORS not supported'); return; } // Response handlers. xhr.onload = function() { var text = xhr.responseText; var title = getTitle(text); alert('Response from CORS request to ' + url + ': ' + title); }; xhr.onerror = function() { alert('Woops, there was an error making the request.'); }; xhr.send(); } 

이에서입니다. 'Access-Control-Allow-Origin'헤더가 요청 된 리소스에 없습니다. 따라서 'http : // localhost : xyz'는 액세스가 허용되지 않습니다. 응답에는 HTTP 상태 코드 401이 있습니다. 위의 코드를 실행하는 동안 오류가 발생했습니다. –

관련 문제