I am creating a web application using OpenLayers 3 and I am looking to import my vector layers into this. I currently have my data in Geoserver and I am trying to use the following code, but when I make the below request using jQuery:

    var vectorLoader = function(extent, resolution, projection) {
    var url = 'http://XXX185:8080/geoserver/wfs?service=WFS&' +
        'version=1.1.0&request=GetFeature&typename=YYY:QGIS&' +
        'outputFormat=text/javascript&format_options=callback:loadFeatures' +
        '&srsname=EPSG:3857&bbox=' + extent.join(',') + ',EPSG:3857';
      url: url,
      dataType: 'jsonp'

  var loadFeatures = function(response) {
    var features = vectorSource.readFeatures(response);

  var vectorSource = new ol.source.ServerVector({
    format: new ol.format.GeoJSON(),
    loader: vectorLoader,
    strategy: ol.loadingstrategy.createTile(new ol.tilegrid.XYZ({
      maxZoom: 19

  var serverVector = new ol.layer.Vector({
    source: vectorSource,
    style: vectorStyle

I get this error:

Uncaught SyntaxError: Unexpected token <
jquery-latest.min.js:4 Resource interpreted as Script but transferred with MIME type application/xml: "http://XXXpc185:8080/geoserver/wfs?service=WFS&version=1.1.0&request=GetFea…SG:3857&callback=jQuery111109427054924890399_1428089051875&_=1428089051876".

I imagine it is something to do with the way the vectorLoader is requesting the WFS?


Did you enabled geoserver JSONP settings in web.xml


contains settings like this:


You should change ENABLE_JSONP as true

  • Just checked the web.xml file and it had already been set to true so this doesn't look like it is the issue. – Joshua Dickerson Apr 3 '15 at 20:50
  • I have applied your setting to a sample server, it works: giswebservices.massgis.state.ma.us/geoserver/… – boliwe Apr 4 '15 at 7:35
  • Try to get your url on browser firs. – boliwe Apr 4 '15 at 7:36
  • Glad to see the settings work, still seems like I haven't got something set up correctly yet, i may need to re-write the wat the vector loader requests the json? – Joshua Dickerson Apr 4 '15 at 18:18
  • 1
    Resolved: After further investigation, the JSONP settings within the web.xml file were not exactly correct and following the answer by @Bayram this now works. Thanks! – Joshua Dickerson Apr 5 '15 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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