I set up a WMS with QGIS SERVER. I am querying it via a web app based on OpenLayers.

Everytime I click on my map, I send a GetFeatureInfo to a specific layer passing the coordinates where I clicked, and the response is rendered in a popup. So far so good.

The problem is if I click where there's no layer's feature in the map, I'd like no popup to show up, but instead I get an "empty-table-response" from the WMS which is in turn rendered in my popup, and this is annoying.

Here is an example of a request with some interesting data:


And here is one with empty data which I don't want to display in the popup:


This is how I am requesting the data in OL (only the relevant part):

function getInfoUrl(evt, view, lyr) {
    var coordinate = evt.coordinate;
    var url = CORS_PREFIX;
    var viewResolution = /** @type {number} */ (view.getResolution());
    if (lyr.get('type') != 'base') {
        var visible = lyr.getVisible();
        if (visible) {
            url += lyr.get('source').getGetFeatureInfoUrl(evt.coordinate, viewResolution, 'EPSG:3857', {
                'INFO_FORMAT': 'text/xml'
            return url;

map.on('singleclick', function(evt) {
        // display info in fancyAlert
        for (let i = 0; i < ol_layers.length; ++i) {
            let layer = ol_layers[i];
            let text = getInfoUrl(evt, view, layer);
            if (text) {

                var xhttp = new XMLHttpRequest();
                xhttp.onreadystatechange = function() {
                    if (this.readyState == 4 && this.status == 200) {
                        fancyAlert(this.responseText, 'info', 'Layer Info');
                xhttp.open("GET", text, true);

How should I avoid the second response to show up? I thought a request to an empty feature area should trigger no response or at least a WMS exception. Maybe this is not a standard but it's what I was used to.

1 Answer 1


If it's not your own service it's unlikely you can change the output. In that specific case you could check if the output contains at least two html tables before displaying it

if (this.readyState == 4 && this.status == 200) {
    if (this.responseText.indexOf('</TABLE>') != this.responseText.lastIndexOf('</TABLE>')) {
        fancyAlert(this.responseText, 'info', 'Layer Info');
  • it is my service. In that case, is there an alternative? Anyway, your solution might be good enough, I'll test it asap and tell you if it works fine for my case.
    – umbe1987
    Jan 26, 2019 at 8:44
  • 1
    It seems similar to other WMS have I checked. Although the output varies between services it is always a status 200 response with valid html (typically comments and styles, but in your case a header table) and a client always needs to check if there is also displayable data embedded it to avoid an empty popup.
    – Mike
    Jan 26, 2019 at 10:52

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .