4

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

6
  • 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
    Commented Dec 9, 2013 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/… Commented Dec 9, 2013 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
    Commented Dec 9, 2013 at 16:03
  • The comment I wrote on the other question you are pointing to might be of some help for you.
    – Decio
    Commented Dec 10, 2013 at 13:25
  • finnaly, i try to use php proxy to get the json data. . in its work. . :) Commented Dec 10, 2013 at 14:04

1 Answer 1

1

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 and acknowledge you have read our privacy policy.

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