Javascript-CORS无响应

Javascript-CORS无响应,javascript,xmlhttprequest,cors,cross-domain,Javascript,Xmlhttprequest,Cors,Cross Domain,我的网站: 要从以下位置添加Metar读数: 我想在CORS中使用Javascript 以下是代码(从其他复制): 但是没有回应 我在日志中有此错误: XMLHttpRequest无法加载…pe=retrieve&format=csv&hoursBeforeNow=3&mostRecent=true&stationString=EIDW。请求的资源上不存在“Access Control Allow Origin”标头。因此,不允许访问源“” 我使用python urllib2获取有效数据,因为这

我的网站:

要从以下位置添加Metar读数:

我想在CORS中使用Javascript

以下是代码(从其他复制):

但是没有回应

我在日志中有此错误:

XMLHttpRequest无法加载…pe=retrieve&format=csv&hoursBeforeNow=3&mostRecent=true&stationString=EIDW。请求的资源上不存在“Access Control Allow Origin”标头。因此,不允许访问源“”


我使用python urllib2获取有效数据,因为这是有用的…

很可能是服务器不支持CORS请求。您是否尝试从web服务器调用此服务并创建自己的web服务来为您的页面提供服务?

看起来服务器可能不支持此功能:对与您的页面域不同的域执行了XMLHttpRequest。这要求服务器在其响应头中返回“Access Control Allow Origin”头,但没有返回。服务器必须支持CORS请求,并随资源返回适当的“Access Control Allow Origin”头。有关响应头中CORS的更多信息,请参见IE10中的CORS for XHR。如果是这样的话。我的选项是什么?一个选项是在web服务器中创建一个页面,该页面将向aviationweather发出请求,然后以文本或json或其他形式返回结果,并通过javascript调用此页面。Instedi的访问权限非常有限。我的网站是一个博客的包装。所以你坚持使用java脚本:(为什么不为weather report@vic152找到另一个域呢?)我在网上找到了这个:我不是一个大的网络程序员,所以对我来说是双重负担…@vic152找到另一个域就行了。
<script language="Javascript">

// Create the XHR object.
function createCORSRequest(method, url) {
  var xhr = new XMLHttpRequest();

  if ("withCredentials" in xhr) {
    // XHR for Chrome/Firefox/Opera/Safari.
    xhr.open(method, url, true);
xhr.setRequestHeader('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8')
  } else if (typeof XDomainRequest != "undefined") {
    // XDomainRequest for IE.
    xhr = new XDomainRequest();
    xhr.open(method, url);
  } else {
    // CORS not supported.
    xhr = null;
  }
  return xhr;
}

// Helper method to parse the title tag from the response.
function getTitle(text) {
  return text.match('<title>(.*)?</title>')[1];
}

// Make the actual CORS request.
function makeCorsRequest() {
  // All HTML5 Rocks properties support CORS.
  var url = 'https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=csv&hoursBeforeNow=3&mostRecent=true&stationString=EIDW';

  var xhr = createCORSRequest('GET', url);
      xhr.setRequestHeader('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8')
      //xhr.setRequestHeader("Access-Control-Allow-Origin", '*');
  if (!xhr) {
    alert('CORS not supported');
    return;
  }

  // Response handlers.
  xhr.onload = function() {
    var text = xhr.responseText;
    var title = getTitle(text);
    alert(text);
    //alert('Response from CORS request to ' + url + ': ' + title);
  };

  xhr.onerror = function() {
    //alert('Woops, there was an error making the request.');
    alert(xhr.statusText);
  };

  xhr.send();
}

makeCorsRequest()

</script>
**General**
    Request URL:https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=csv&hoursBeforeNow=3&mostRecent=true&stationString=EIDW
    Request Method:GET
    Status Code:200 OK
    Remote Address:140.90.101.207:443

**Response Headers**

Connection:Keep-Alive
Content-Type:application/x-csv
Date:Wed, 13 Apr 2016 21:28:12 GMT
Keep-Alive:timeout=300, max=98
Server:Apache-Coyote/1.1
Transfer-Encoding:chunked
Via:1.1 aviationweather.ncep.noaa.gov
X-Content-Type-Options:nosniff
X-Frame-Options:SAMEORIGIN
X-XSS-Protection:1; mode=block

**Request Headers**

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8, text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
DNT:1
Host:www.aviationweather.gov
Origin:http://www.bluegreenblack.com
Referer:http://www.bluegreenblack.com/p/weather-in-ireland.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36

**Query String Parameters**

view URL encoded
dataSource:metars
requestType:retrieve
format:csv
hoursBeforeNow:3
mostRecent:true
stationString:EIDW