我正在尝试使用Prototype/AJAX访问Web服务,但遇到一个无法解决的错误:当我向服务器发出请求时,我的请求被解释为OPTIONS而不是GET请求(因此根据我从
以下是相关的AJAX请求:
我可能忽略了什么?为什么Chrome说请求是以OPTIONS而不是GET发送的?当Chrome输出
Access-Control-Request-Method:
中了解到的内容,会引发501-未实现的错误,因为服务器只允许GET请求)。 我在AJAX / request公式中是否缺少某些东西可能导致此错误? 我已经阅读了一些关于CORS /预检请求的信息在这里,但我不确定它如何适用于我的代码看起来是符合规范的...以下是相关的AJAX请求:
function fetchMetar() {
var station_id = $("station_input").value;
new Ajax.Request(REQUEST_ADDRESS, {
method: "get",
parameters: {stationString: station_id},
onSuccess: displayMetar,
onFailure: function() {
$("errors").update("an error occurred");
}
});
}
这里是我从Chrome得到的错误和相关请求信息:
Request URL:http://weather.aero/dataserver_current/httpparam?
dataSource=metars&requestType=retrieve&format=xml&hoursBeforeNow=3
&mostRecent=true&stationString=&stationString=KSBA
Request Method:OPTIONS
Status Code:501 Not Implemented
Request Headers
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:origin, x-prototype-version, x-requested-with, accept
Access-Control-Request-Method:GET
Connection:keep-alive
Host:weather.aero
Origin:http://domain.com
Referer:http://domain.com/.../...html
我可能忽略了什么?为什么Chrome说请求是以OPTIONS而不是GET发送的?当Chrome输出
Access-Control-Request-Headers:
信息时,这些是否是请求中允许的唯一标头?谢谢!