Reputation: 23
Apologies in advance, this is a real 'training wheels question'. I am following the instructions on the FRED API (Federal Reserve Bank of St.Louis) website for the HTTP Get request and I keep getting cross-origin errors, but can't find any documentation on how to fix the code.
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", "http://api.stlouisfed.org/fred/releases/dates?api_key=1cee0e87e5e3362716028352d3d1c160", false );
xmlHttp.send( null );
return xmlHttp.responseText;
Everything syntaxically is correct, I thought using the site-defined API key would be the only 'authentication' and would let me through?
This is the example link: St.Louis Fed Web Services I have been googling/messing with code for the last 5 hours, can anyone weigh in? thanks
Upvotes: 0
Views: 670
Reputation: 4339
Web browsers prohibit cross-domain http requests unless the service you request the data from explicitly allows it, which is specified in the "control access allow origin" header on the http response. Unfortunately, FRED has chosen not to allow them. You aren't doing anything wrong in the code above, there's just no way to do this in a web browser.
I think the goal for the FRED API is to allow researchers to download the data directly into statistical applications like STATA and SAS. They apparently don't want people using the API to build web applications.
Upvotes: 1