1

I'm creating an web map application using Geoserver and Leaflet. I'm trying to load a few Json feature through an WFS service.The problem is that nothing is being displayed on the final map, the Geoserver console emits the following meassage: [info.json] - about to encode JSON

What makes me to believe that there is nothing wrong with the service.

Here is the code.

var map = L.map('map').setView([39.752171, -104.998817], 17);
L.tileLayer('https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png', {
 maxZoom: 18,
 attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
 '<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
 'Imagery © <a href="http://mapbox.com">Mapbox</a>',
 id: 'examples.map-20v6611k'
 }).addTo(map);
var geojsonLayer = new L.GeoJSON();
function handleJson(data) {
console.log(data)
geojsonLayer.addData(data);
}
var geoJsonUrl = "http://localhost:8080/geoserver/PastDenver/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=PastDenver:dataset1&maxFeatures=50&outputFormat=text/javascript&format_options=callback:getJson"
$.ajax({
url : geoJsonUrl,
dataType : 'json',
jsonpCallback: 'getJson',
success : handleJson
});
map.addLayer(geojsonLayer);

Most of this code I took from examples from here, I have no idea what may be happening.

Does the version of JQuery matters from this AJAX? I'm using this link https://code.jquery.com/jquery-2.1.3.js

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Feb 3, 2015 at 4:43
3
  • what does the browser console show when you console.log the json response? Commented Feb 3, 2015 at 5:04
  • http://localhost:8080/geoserver/PastDenver/ows?service=WFS&version=1.0.0&re...xFeatures=300&outputFormat=text/javascript&format_options=callback:getJson. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. Commented Feb 3, 2015 at 15:01
  • Chris' answer worked just fine, now I would like to understand the relationship between that mistake and this error. Commented Feb 3, 2015 at 15:03

2 Answers 2

3

Try to change the dataType in your ajax request to 'jsonp'

The documentation indicates

callback—Applies only to the JSONP output format.

answered Feb 3, 2015 at 5:15
1
  • I swear that I tried this on the first time. Thanks for hint, not it is displaying! Commented Feb 3, 2015 at 15:00
1

have you looked at this answer? GeoServer 2.3 how to enable jsonp. Depending on your version of GeoServer you may have to edit web.xml

answered Feb 5, 2015 at 0:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.