Take the 2-minute tour ×

I'm trying to consume the USA Today Census API json service using jquery and jsonp. Here is the code:

var url = "http://api.usatoday.com/open/census/locations?api_key=yourapikeyhere&keyname=FIPS&sumlevid=3&keypat=36069&format=jsonp&callback=?";

            url: url,
            dataType: 'jsonp',
            type: 'GET',
            success: function (result) {

Here is the response if I hit the url in the browser, which is valid json:


    {"Placename":"Ontario","PlacenameFull":"Ontario County, N.Y.","FIPS":"36069","GNIS":"974133","StateAP":"N.Y.","StatePostal":"NY",


Firebug gives an "invalid label" error and doesn't return the result. Any ideas?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

I updated the server, to support JSONP. (I would have done it earlier, but I just got back from vacation.)

share|improve this answer
Works like a charm now, thanks!! –  Justin Sep 9 '11 at 17:12
add comment

It seem that the API you are using doesn't supports JSONP (the response is not wrapped in a function call). And when the script is executed it results in a syntax error because hash literals ({...}) are not allowed as top-level statements.

Make sure that the API supports JSONP, and if it does, make sure that you are using the correct name for the callback parameter.

If it doesn't supports JSONP you'll have to call it through a server-side language (or proxy requests to it).

JSONP works by wrapping a javascript literal in a function call, for example:

jsonp_callback({the: "response"});

If you implement fhe function jsonp_callback() and execute this script, your function will receive the response.

The server must explicitly support JSONP for this to work.

share|improve this answer
add comment

Your Answer


