Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I overwrite the url of OpenLayers.Protocol.HTTP? I tried


and it works (checked with console.log), but at the end the original url is sent (in the code below: url: '/fs/') (see attached picture).

output from firebug

This is the code:

var searchformPanel = new GeoExt.form.FormPanel({
  border: false,
  width: 250,
  protocol: new OpenLayers.Protocol.HTTP({
    url: '/fs/',
    format: new OpenLayers.Format.GeoJSON()
    xtype: 'combo',
    id: 'idcombo',
    store: new{
      data:[["Boreholes","Boreholes"],["All_layers","All layers"]]
    displayField: 'ollayer',
    valueField: 'fsclass',
    fieldLabel: 'Layer',
    emptyText: 'select a layer',
    submitValue: false,
    selectOnFocus: true,
    mode: 'local',
    typeAhead: true,
    editable: false,
    forceSelection: true,
    triggerAction: 'all'
    xtype: 'textfield',
    id: 'idtextfield',
    fieldLabel: 'Find features',
    emptyText: 'enter word',
    name: 'comments__like',
    allowBlank: false
    actioncomplete: function(form, action){
    text: 'search',
      click: function(){

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

        var newUrl = '/fs/' + comboLayer + '?format=GeoJSON&comments__ilike=' + keyword + '&queryable=comments';
        console.log('1:' + newUrl);

        //this gets '/fs/' from the searchformPanel
        console.log('2:' + searchformPanel.protocol.url);

        searchformPanel.protocol.url = newUrl;
        console.log('3:' + searchformPanel.protocol.url);;


Please any support about this is very welcome, thank you!

share|improve this question
up vote 0 down vote accepted

Finally it worked!!!!!!!!! the trick was to take the protocol outside the formPanel and there replace the newUrl as "protocol.options.url = newUrl;". I didn't know about this "options" until I checked the line 180 of HTTP.js of OpenLayers, because I tried to use and I received an error pointing to this line (as explained here). Also, I was resending the "comments" and "queryables" of the formPanel (so I deleted "keyword" above), as it was posted by myself in this original question. Here is the piece of code that did the trick, simple and beautiful:

buttons: [{
    text: 'Search',
    handler: function() {
        comboLayer = Ext.getCmp('idcombo').getValue();
        newUrl = '/fs/' + comboLayer + '?format=GeoJSON';
        protocol.options.url = newUrl;;

Also, I was confused about how variables and local/global scope work together, I think I came up with this solution because I understood that writing things inside "functions" (because all the above is inside a function() called in the handler) make that variables are being read by another variables before and after the function is declared, not sure if it's clear what I explained before, but sure this link explains it much better.

Hope this helps more people, especially those new in javascript and openlayers like me!!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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