簡體   English   中英

OpenLayers正在發出HTTP OPTION請求?

[英]OpenLayers is making HTTP OPTION requests?

前一段時間,由於stackoverflow,我有了這個小提琴: http : //jsfiddle.net/AUbZn/16/現在不復存在了:/

似乎無論出於何種原因,請求都是通過OPTION方法發送到yahoo的。 這是相關的部分,因為該網址是option'ed:

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
},
});

知道為什么以及如何糾正它嗎?

找到了解決方案:)

在此示例之后,使用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
    },
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM