I am trying to connect a WMS layer from GeoServer with OpenLayers 3 like below, however, my JavaScript file does not show my WMS layer.

My Chrome says it failed to load response data (WMS). My source is redirected to below URL. This URL works on my server, but not through the JavaScript source.


Can someone please help?

It seems like the problem is caused from security settings in GeoServer and I tried to create roles to getread() as well. (http://docs.geoserver.org/stable/en/user/security/service.html)

enter image description here

var layers = [
 new ol.layer.Tile({
 extent: [-13884991, 2870341, -7455066, 6338219],
 source: new ol.source.TileWMS({
  url: "http://localhost:8080/geoserver/Mars/wms",
  params: {'layers': 'Mars:Mercury_basemap', 'tiled': true, 'format': 'application/openlayers', 'srs': 'EPSG:4326', 'transparent': true},
  serverType: 'geoserver'

var map = new ol.Map({
 layers: layers,
 target: 'map',
 view: new ol.View({
   center: [-10997148, 4569099],
   zoom: 4
  • You should drop srs=EPSG%3A4326& as it's the wrong parameter to request your coordinate reference system for a WMS 1.3.0 GetMap request. You also have the correct parameter though as CRS=EPSG%3A3857&
    – nmtoken
    Commented Apr 4, 2018 at 18:24
  • Thank you all for your help. After doing what you all suggested, it still did not work(Obviously I was a few steps closer to the answer though). The simple solution was opening the port - I just opened my port 8080 in the firewall and opened my map.
    – Jaeho Shin
    Commented Apr 6, 2018 at 14:46

2 Answers 2


You are asking geoserver to return a javascript application rather than the image that openlayers is expecting.

Remove the format parameter and the srs and tiled ones too.


localhost is the machine running the code, so it would work only if ran on the server itself. You would need to set the URL to your server URL instead


url: "http://localhost:8080/geoserver/Mars/wms",

to something like

 url: "http://www.myDomain.Com:8080/geoserver/Mars/wms",


 url: "",

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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