2012-05-15 1 views
1

javascript 및 jQuery를 사용하여 API에 액세스하려고하는데 이상한 오류가 발생합니다.jQuery의 도메인 간 요청은 특정 파일에서만 작동합니다.

$(document).ready(function() { 
    var server = 'https://' + rand(10) + '.spotilocal.com:4371'; 
    $.getJSON(
     server + "/service/version.json?service=remote&_=" + new Date().getTime(), 
     function(data) { 
      if (data.version == 9) { 
       $.getJSON(
        server + "/simplecsrf/token.json?&cors=&_=" + new Date().getTime(), 
        function(data) { 
         console.log(data.toString()); 
       }); 
      } 
    }); 

    function rand(length,current){ 
     // returns a random string 
    } 
}); 

내 오류 :

XHR finished loading: "https://rwhpxmubmi.spotilocal.com:4371/service/version.json?service=remote&_=1337093238805". 
XMLHttpRequest cannot load https://rwhpxmubmi.spotilocal.com:4371/simplecsrf/token.json?&cors=&_=1337093239623. Origin http://example.com is not allowed by Access-Control-Allow-Origin. 

첫 번째 요청이 성공하지만 두 번째는 실패합니다. 그러나 두 파일은 모두 동일한 서버에 있으며 두 파일 모두 JSON입니다.

이 오류가 발생하는 이유와 해결 방법을 아는 사람이 있습니까?

답변

1

파일의 헤더를 편집해야합니다. 그들 중 하나는 분명히 Access-Origin이 적절히 설정되어 있고 다른 하나는 그렇지 않습니다.

체크 아웃은 page입니다.

+0

예, 문제가 있습니다. 감사합니다. – Qurben