Search code examples
openlayersjavascript

"TypeError: this.options is null" in OpenLayers.Protocol.HTTP‏


I'm using OL 2.11 with GeoExt 1.1. After testing and modifying this GeoExt example: http://geoext.org/lib/GeoExt/widgets/form/FormPanel.html, I had problems with destroying and reading the new protocol, I'm getting "TypeError: this.options is null HTTP.js (line 180)" in firebug. What I understand from this line 180 is that the new options (in the new protocol) are not there, not sure if this is the problem and how to solve it. This is the original protocol (created outside the FormPanel):

protocol = new OpenLayers.Protocol.HTTP({
    url: '/fs/',
    format: new OpenLayers.Format.GeoJSON({
        ignoreExtraDims: true,
        'internalProjection': new OpenLayers.Projection('EPSG:900913'),
        'externalProjection': new OpenLayers.Projection('EPSG:4326')
    })
});

This is the code at the end of the FormPanel where the new protocol is created:

    buttons: [{
        text: 'Search',
        handler: function() {

            comboLayer = Ext.getCmp('idcombo').getValue();
            keyword = Ext.getCmp('idtextfield').getRawValue();

            protocol.destroy();

            protocol = new OpenLayers.Protocol.HTTP({
                url: '/fs/' + comboLayer + '?format=GeoJSON&comments__ilike=' + keyword + '&queryable=comments',
                format: new OpenLayers.Format.GeoJSON({
                    ignoreExtraDims: true,
                    'internalProjection': new OpenLayers.Projection('EPSG:900913'),
                    'externalProjection': new OpenLayers.Projection('EPSG:4326')
                })
            });

            protocol.read();

            formPanel.search();
        }
    }]

In the case I remove "protocol.destroy();", both the original and the new protocols are sent, but always the original is sent after the new one, this happens because the request is AJAX? is it possible to send the new after the original?

I'd appreciate some support on this, thanks in advance,


Solution

  • The solution was to use only "protocol.options.url = newUrl;" instead of protocol.destroy(); or protocol.read();, a complete explanation is here