I try to call json data from geoserver,
but when i try to run it in chrome, it return this following error
"Uncaught SyntaxError: Unexpected token :"
This is my code,
function initialize(){var urljson='http://localhost:1234/geoserver/Ven/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=Ven:alamatpuskesmas&maxFeatures=50&outputFormat=json&format_options=callback:getJson';
$.ajax({
url :urljson,
dataType: 'jsonp',
jsonpCallback: 'getJson',
success: handleJson
});
}
function handleJson(data)
{
console.log(data);
}
i am using geoserver 2.4.2, whats wrong with my code?,
when i try to paste the url in chrome/firefox, it return json. .
Best Answer
If you change your
var urljson
to the following and changejsonCallback:getJson
tojsonCallback:parseResponse
, then it should work:The part that needs to change is the
outputFormat
. It needs to betext/javascript
and notjson
.More information can be found in this tutorial.