Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm making a simple GetFeatureInfo request against a GeoServer WMS, but it returns empty responses. The request utility I'm using is OpenLayers.loadURL.

The funny thing is, I can paste the generated request URL from FireBug into a new browser tab and get a valid response. So, it seems to be something with the OpenLayers.loadURL. See the examples below.

I can get a valid response with this map event where the GetFeatureInfo request is in a new window:

  map.events.register('click', map, function (e) {
    var url = "http://localhost:8080/geoserver/MYLAYER/wms" 
    var params = "" 
      + "REQUEST=GetFeatureInfo"
      + "&SERVICE=WMS"
      + "&EXCEPTIONS=application/vnd.ogc.se_xml"
      + "&VERSION=1.1.1"
      + "&BBOX=" + map.getExtent().toBBOX()
      + "&X=" + Math.round(e.xy.x)
      + "&Y=" + Math.round(e.xy.y)
      + "&INFO_FORMAT=text/html"
      + "&QUERY_LAYERS=NERD:NERD Risk Rates"
      + "&LAYERS=NERD:NERD Risk Rates"
      + "&FEATURE_COUNT=50"
      + "&format=image/png"
      + "&SRS=EPSG:900913"
      + "&STYLES="
      + "&WIDTH=" + map.size.w
      + "&HEIGHT=" + map.size.h;

    console.log(url+"?"+params);
    window.open(url+"?"+params,
      "getfeatureinfo",
      "location=0,status=0,scrollbars=1,width=600,height=150"
    );

   });

However, this map event using OpenLayers.loadURL always returns an empty response and no error. But if I cut and paste the GET request url from FireBug into a new browser window, I get the proper response:

  map.events.register('click', map, function (e) {
    var url = "http://localhost:8080/geoserver/MYLAYER/wms" 

    var paramHash =  {
      REQUEST : "GetFeatureInfo" ,
      EXCEPTIONS : "application/vnd.ogc.se_xml" ,
      SERVICE : "WMS" , 
      VERSION : "1.1.1" ,
      BBOX : map.getExtent().toBBOX() ,
      X : Math.round(e.xy.x) ,
      Y : Math.round(e.xy.y) ,
      INFO_FORMAT : "text/html" , 
      QUERY_LAYERS : "NERD:NERD Risk Rates" , 
      LAYERS : "NERD:NERD Risk Rates" ,
      FEATURE_COUNT : 50 , 
      format : "image/png" ,
      srs : "EPSG:900913" ,
      styles : "" ,
      WIDTH : map.size.w , 
      HEIGHT : map.size.h
    };

    OpenLayers.loadURL(url, paramHash, this, setHTML, setHTML);
        OpenLayers.Event.stop(e);

   });

Someone have any ideas?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Sounds like a same origin problem to me. Are you serving your page from a different host/port combination than the map server? See http://trac.osgeo.org/openlayers/wiki/FrequentlyAskedQuestions#ProxyHost for details of how to fix this using a proxy or move your html page to data/web in your geoserver installation.

share|improve this answer
1  
Yes, you are correct. So now I'm trying to serve my static html page out of apache-tomcat geoserver project as described here docs.geoserver.org/latest/en/user/tutorials/staticfiles.html. There is already html in the directory /var/lib/tomcat6/webapps/geoserver/data/www such as ol-demo.html. I can see this html if i go to localhost:8080/geoserver/www/ol-demo.html. But if i stick my html in this directory and try to go to the URL I only get a 404? Any ideas about that? –  maztaz Feb 1 '12 at 12:22
    
/usr/share/opengeo-suite-data not the actual tomcat directory. ugh –  maztaz Feb 1 '12 at 12:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.