[Q&A] How do I parse getStyle request? Get SLD GeoServer

I am having problem parsing

getStyle response from geoserver of layer topp:states. I want to get the SLD information of a layer with openlayers. I get blank response for the following request. The response parsed SLD file has no value. For now I am doing :

The response:

But when I hit direct requested url I get right sld.

The SLD with url directly on address bar:

2 Answers

up vote2down voteaccepted

+50

It seems the problem is in the line breaks from Geoserver XML indent.

It works when I do something like below

Edit

When I do my test going to http://localhost:8080/geoserver/topp/wms?service=WMS&version=1.1.0&request=GetMap&layers=topp:states&styles=&bbox=-124.73142200000001,24.955967,-66.969849,49.371735&width=780&height=330&srs=EPSG:4326&format=application/openlayers, it failed.

I solved the problem by replacing the file OpenLayers.js into the geoserver/WEB-INF/lib/wms-2.3.1.jar with the http://openlayers.org/dev/OpenLayers.js (because the default built-in Openlayers library in Geoserver don’t have OpenLayers.Format.SLD() and OpenLayers.Format.JSON())

If you don’t want to change anything but only confirm it works just try with this other ajax request

If you always have a blank answer with code below, look on the Cross Domain Policy matter. It’s a common problem with ajax calls. See http://www.gistutor.com/geoserver/21-intermediate-geoserver-tutorials/38-configuring-geoserver-proxy-for-public-and-remote-data-access.html