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';

                    url :urljson,
                    dataType: 'jsonp',
                    jsonpCallback: 'getJson',
                    success: handleJson

        function handleJson(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. .

  • You have some syntax error in your JavaScript somewhere. Try looking at the error message again in Chrome, it should follow with a link that points to the error in your code. – Decio Dec 9 '13 at 15:45
  • there is no error in my javascript code, the only error message in chrome is Uncaught SyntaxError: Unexpected token : error link is at ows:1 i got same error with this post gis.stackexchange.com/questions/79319/… – Dea Venditama Dec 9 '13 at 15:54
  • I can not see how geoserver has anything to do with the error here, but I am missing the bigger picture... What is ows? – Decio Dec 9 '13 at 16:03
  • The comment I wrote on the other question you are pointing to might be of some help for you. – Decio Dec 10 '13 at 13:25
  • finnaly, i try to use php proxy to get the json data. . in its work. . :) – Dea Venditama Dec 10 '13 at 14:04

If you change your var urljson to the following and change jsonCallback:getJson to jsonCallback:parseResponse, then it should work:

var urljson='http://localhost:1234/geoserver/Ven/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=Ven:alamatpuskesmas&maxFeatures=50&outputFormat=text/javascript&format_options=callback:getJson';

The part that needs to change is the outputFormat. It needs to be text/javascript and not json.

More information can be found in this tutorial.

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.