OpenLayers正在发出HTTP OPTION请求?

时间:2013-01-12 00:00:01

标签: javascript http openlayers yql gml

前一段时间,由于stackoverflow,我有这个小提琴工作:http://jsfiddle.net/AUbZn/16/现在已经不存在了:/

似乎无论出于何种原因,请求都是以OPTION方式发送给yahoo的。 这是相关部分,因为这个网址是可选的:

var layer = new OpenLayers.Layer.Vector("GML", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
    url: "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Fopenlayers.org%2Fdev%2Fexamples%2Fgml%2Fpolygon.xml'",
    format: new OpenLayers.Format.GML(),
}),
eventListeners: {
    "featuresadded": dataLoaded
},
});

知道为什么以及如何纠正它?

1 个答案:

答案 0 :(得分:0)

找到解决方案:)

在此示例后使用OpenLayers.Protocol.Script而不是OpenLayers.Protocol.HTTP:http://openlayers.org/dev/examples/cross-origin-xml.html

工作代码:

var layer = new OpenLayers.Layer.Vector("GML", {
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.Script({
        url: "http://query.yahooapis.com/v1/public/yql",
        params: {
            q: "select * from xml where url='http%3A%2F%2Fopenlayers.org%2Fdev%2Fexamples%2Fgml%2Fpolygon.xml'",
        },
        format: new OpenLayers.Format.GML(),
        parseFeatures: function(data) {
            return this.format.read(data.results[0]);
        },
    }),
    eventListeners: {
        "featuresadded": featuresLoaded
    },
});