Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm in this scenario (fighting with the same origin police issue):

I have a map initialized with OpenLayers and a WFS request trough the Protocol.Script object that is giving me this error:

Uncaught TypeError: Object function (a,b){this.metadata={};b=OpenLayers.Util.extend({},b);null!=this.alwaysInRange&&(b.alwaysInRange=this.alwaysInRange);this.addOptions(b);this.name=a;if(null==this.id&&(this.id=OpenLayers.Util.createUniqueID(this.CLASS_NAME+"_"),this.div=OpenLayers.Util.createDiv(this.id),this.div.style.width="100%",this.div.style.height="100%",this.div.dir="ltr",this.events=new OpenLayers.Events(this,
this.div),this.eventListeners instanceof Object))this.events.on(this.eventListeners)} has no method 'addOptions' 

The error seems to be related with OpenLayers lib (maybe the version, actually is the 2.13), but i don't know.

What i tried is:

consulados = OpenLayers.Layer.Vector("Consulados", {
        strategies: [new OpenLayers.Strategy.BBOX()],
        protocol: new OpenLayers.Protocol.Script({
            url: "http://"+ip+':'+port+"/geoserver/wfs",
            callback: 'handleResponse',
            params: {
                service: "WFS",
                version: "1.1.0",
                srsName: "EPSG:4326",
                request: "GetFeature",
                typeName: "topp:tazmania_roads",
                outputFormat: "text/javascript"
            },
        })
});

Any help is appreciated.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Finally a solution was found.

I decided to lay aside openlayers and make a try with simply a jQuery.ajax request. Take care with the url. Here you can found details to build the request url Geoserver output formats

var url = "http://"+ip+":"+port+"/geoserver/ows?service=WFS&version=1.0.0&request=GetFeature&typeName= topp:tazmania_roads&outputFormat=text/javascript&format_options=callback:getJson";

jQuery.ajax({
                    jsonp: false,
                    jsonpCallback: 'getJson',
                    type: 'GET',
                    url: url,
                    async: false,
                    dataType: 'jsonp',
                    success: function(jsonObject) {
                        alert(jsonObject);
                        //handler(jsonObject);
                        create_GeoJSON(jsonObject);
                    }
});

When the client side receives the data (if there isn't any errors) success "body" is called to manage the JSON object and work with this.

share|improve this answer
add comment

Your Answer

 
discard

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.