I'm trying to access plain text weather data with a CORS/cross-domain get request from http://weather.noaa.gov and (reasonably obviously) I have no control over the server. The calling web page is plain HTML (ie no PHP, no ASP.NET).
The URL I'm calling for the moment is: http://weather.noaa.gov/pub/data/observations/metar/stations/LFBL.TXT and that works fine in Fiddler with the following raw response:
HTTP/1.1 200 OK
Server: Apache
ETag: "526b614-4b-5263c79234bbe"
Last-Modified: Sun, 06 Dec 2015 15:34:15 GMT
Accept-Ranges: bytes
Content-Length: 75
Content-Type: text/plain; charset=UTF-8
Cache-Control: max-age=168
Expires: Sun, 06 Dec 2015 15:44:26 GMT
Date: Sun, 06 Dec 2015 15:41:38 GMT
Connection: keep-alive
2015/12/06 15:30
LFBL 061530Z AUTO 14004KT 100V170 9999 ///TCU 12/07 Q1028
I'm using jQuery 2.1.4 and the JavaScript function that I'm using to make the call is as follows:
function getWeather(station)
{
station = station.toUpperCase();
$.ajax(
{
url: 'http://weather.noaa.gov/pub/data/observations/metar/stations/' + station + '.TXT',
type: "GET",
//headers: { "Access-Control-Allow-Origin" : "*" } ,
//beforeSend: function(xhr)
// {
// xhr.setRequestHeader( 'Access-Control-Allow-Origin' , '*' )
// },
dataType: "text",
crossDomain: true,
success: function(data)
{
return data;
},
error : function()
{
return "No METAR/TAF data available for the station '" + station + "'";
}
});
}
As shown, with the header bits commented out, the browser is rejecting the GET request with:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
So I tried a preflight calls using setRequestHeader above but the server gives this response:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
So I'm in a situation where I have to add an Access-Control-Allow-Origin header to the request but the server isn't responding appropriately (I repeat, I have no control over that) and so the call is being blocked.
Is there an error or missing configuration item in my code? Or is it impossible to retrieve text, as opposed to say XML or JSON, from a cross-domain website?