[GIS] Uncaught SyntaxError: Unexpected token : when using ajax

ajaxgeoserverjavascriptjquery

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 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.