2017-12-19 7 views
1

언젠가 다른 AJAX 웹 사이트가 더 이상 작동하지 않기를 바란다는 이상한 문제가 있습니다.CORS가 더 이상 작동하지 않습니다.

지금은 제대로 작동하지 않으므로 문제를 찾을 수 없습니다.

이것은 내 자바 스크립트입니다. 기본적으로 실제로 간단합니다. ip adres를 검색 한 다음 저장합니다 (POST). 난 단지

header('Access-Control-Allow-Origin: '); I got the error: Cross-Origin-request blocked: CORS-header ‘Access-Control-Allow-Origin’ does not match ‘, *’).

을 사용하고 새로운 헤더 내가

CORS-header ‘Access-Control-Allow-Origin’ does not match ‘ http://www.inofec.nl , *’).

를 얻을 때 서버에서
 

    var xhr = new XMLHttpRequest(); 
    xhr.open('GET', 'https://dashboard.inofec.nl/ip', true); 

    // If specified, responseType must be empty string or "text" 
    xhr.responseType = 'text'; 

     xhr.onload = function() { 
      if (xhr.readyState === xhr.DONE) { 
       if (xhr.status === 200) { 
        // console.log('R = ' + xhr.response); 
        // console.log('RT= ' + xhr.responseText); 
        tip = xhr.responseText; 

        var formData = new FormData(); 
        formData.append('ip', tip); 
        formData.append('uri', turl); 
        formData.append('id', dataId); 

        var request = new XMLHttpRequest(); 
        request.open("POST", "https://dashboard.inofec.nl/visits"); 
        request.send(formData); 

        // console.log('IP = ' + tip); 
        // console.log('URL = ' + turl); 
        console.log('ID = ' + dataId); 
       } 
       else { 
        console.log('ERROR !'); 
       } 
      } 
     } 
    xhr.send(null); 

은 지금 와일드 카드

 

    if (isset($_SERVER['HTTP_ORIGIN']) && $_SERVER['HTTP_ORIGIN'] != '') { 
     header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']); 
     header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS'); 
     header('Access-Control-Max-Age: 1000'); 
     header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With'); 
    } 

을 사용하지 않도록하려면이 옵션을 추가 한

하지만 h를 확인할 때 eaders 나는 그것이 올바른 헤더로 응답 것을 참조하십시오.

Access-control-allow-headers
Content-Type, Authorization, X-Requested-With access-control-allow-methods
GET, PUT, POST, DELETE, OPTIONS access-control-allow-origin http://www.inofec.nl , *

+0

'Access-Control-Allow-Origin :'* ' – zabusa

+0

내가 웹 사이트에 갈 때 "https://dashboard.inofec.nl/ip를로드하지 못했습니다 :'Access-Control-Allow-Origin ' 헤더에는 여러 값 'http://www.inofec.nl, *'이 있지만 하나만 허용됩니다. 'http://www.inofec.nl'의 원본은 액세스 할 수 없습니다. " –

+0

그래서 헤더를 헤더 ('Access-Control-Allow-Origin : *')로 변경했습니다. 그리고 지금은 아직 작동하지 않습니다. 그러나 이제는 응답이 액세스 제어 허용 원점입니다 *, * – mdgeus

답변

0

이보 실론은 저에게 여러 가지 가치에 대해 생각하게했습니다. 그리고 올바른 방향으로 나를 가리켰다.

헤더를 검색 한 결과 웹 서버에 이미 헤더가 설정되어 있고 코드에 추가 된 것으로 나타났습니다.

웹 서버의 헤더 세트를 제거하여 사용 방법 및시기를 제어했습니다.

의견을 보내 주셔서 감사합니다.

관련 문제