0

I got the typical cross-domain problem when access to WFS layer by using openlayers,

XMLHttpRequest cannot load http://XXXX/geoserver/ows?service=WFS. Origin http://XXXX is not allowed by Access-Control-Allow-Origin.

I did some research about how to handle this. it seems that a web proxy solution is a good. so I edited a proxy.py file, and put it at the root of my IIS server. however, it seems that I need to explicitly put the following code somewhere:

Openlayers.ProxyHost = "/cgi-bin/proxy.py?url" 

but I don't know where to put. If I put like below:

var map;
Openlayers.ProxyHost = "/cgi-bin/proxy.py?url"

Ext.OnReady(){ //more code }

It will popup an error saying "OpenLayers is not recognized".

Any hints?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Simon
  • 1,207
  • 4
  • 17
  • 29

1 Answers1

2

You should put that line after you load the OpenLayers javascript file(s) and before you start creating your map

<script src='/path/to/openlayers.js' />
<script>
if(OpenLayers)
{ 
      alert('woo hoo! Open layers object is now loaded'); 
      Openlayers.ProxyHost = "/cgi-bin/proxy.py?url";
}
else
{
      // you shouldn't be seeing this if OL path is correct
      alert('uh-oh! where's my Open Layers object??'); 
}
</script>
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Vadim
  • 3,971
  • 2
  • 29
  • 42