데이터 자금 지원을 위해 OpenFEMA API에 액세스하려고하지만 API에 익숙하지 않고 Javascript를 사용하여 API에 액세스하려고합니다. 나는 Same-Origin Problem을 만났고 CORS를 사용하기 시작했다.특정 API에 액세스
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// Check if the XMLHttpRequest object has a "withCredentials" property.
// "withCredentials" only exists on XMLHTTPRequest2 objects.
xhr.open(method, url, true);
console.log('1');
} else if (typeof XDomainRequest != "undefined") {
// Otherwise, check if XDomainRequest.
// XDomainRequest only exists in IE, and is IE's way of making CORS requests.
xhr = new XDomainRequest();
xhr.open(method, url);
console.log('2');
} else {
// Otherwise, CORS is not supported by the browser.
xhr = null;
console.log('3');
}
return xhr;
}
var xhr = createCORSRequest('GET', "http://www.fema.gov/api/open/v1/PublicAssistanceFundedProjectsDetails");
alert(xhr.responseText);
을하지만가 올 때 경고 상자가 비어 있습니다 :
그래서 내 코드는 현재 다음과 같습니다. 나는 내가 뭘 잘못하고 있는지 정말로 모른다. 도움이 될거야.
죄송합니다. 의미가 무엇인지 모르겠으니 – user2926266
로드 될 때까지 기다려야합니다. –
오케이 이제 데이터 세트가 너무 큽니까? – user2926266