msWMSLoadGetMapParams(): WMS server error. Invalid SRS given : SRS must be valid for all requested layers.

<?xml version='1.0' encoding="ISO-8859-1" standalone="no" ?>
<!DOCTYPE ServiceExceptionReport SYSTEM "http://schemas.opengis.net/wms/1.1.1/exception_1_1_1.dtd">
<ServiceExceptionReport version="1.1.1">
<ServiceException code="InvalidSRS">
msWMSLoadGetMapParams(): WMS server error. Invalid SRS given : SRS must be valid for all requested layers.
</ServiceException>
</ServiceExceptionReport>Code language: HTML, XML (xml)

This error appears when the map variable of Openlayers has a different SRS than the wanted layer. When the SRS of the source for the layer cannot be changed, you can use:

tileLoadFunction(tile, src) { /* code */ }Code language: CSS (css)

Here is a full example of a layer:

var layer = new ol.layer.Tile({
	title: "Title of the layer",
	opacity: 0.7,
	source: new ol.source.TileWMS({
		url: '/sourceUrl',
		params: {
			LAYERS: 'theWantedLayer',
			VERSION: '1.1.1',
			format: 'image/png',
			STYLE: 'default'
		},
		tileLoadFunction: function (tile, src) {
			src = src.replace(/SRS=[^&]+/g, 'SRS=' + window.escape('EPSG:31700'));
			tile.getImage().src = src;
		}
	})
});Code language: JavaScript (javascript)