I Receive Undefined When I Use send(callback)

41 views
Skip to first unread message

William Herbert

unread,
Oct 12, 2011, 3:25:26 PM10/12/11
to google-visua...@googlegroups.com
This is my situation:

I've loaded jsapi/visualization corechart, etc.

I make a call to any datasource (I've tried a public Google Doc and my private service) and when I make the call to an external data source, I believe that it's not passing a value.  When I call response.isError in the callback function, it is reported as undefined.  My code to the public spreadsheet is below:

    <script>
    function firstFunction() {
        var myQuery = new google.visualization.Query(requestURL);
        myQuery.send(createTable);
    }

    function createTable(response) {
      if (response.isError()) {
            alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
            return;
        }
    }

    google.setOnLoadCallback(firstFunction());
    </script>

The error that I see in Chrome's log is
Uncaught TypeError: Cannot call method 'isError' of undefined
Any advice or pointers would be greatly appreciated.

William

NA

unread,
Oct 12, 2011, 7:21:19 PM10/12/11
to Google Visualization API
I think you mean:

google.setOnLoadCallback(firstFunction);

If you use google.setOnLoadCallback(firstFunction()), you will
actually call firstFunction() with no inputs. But
google.setOnLoadCallback(firstFunction) just passes the function
"firstFunction" to the setOnLoadCallback method, which is what you
want.

Try that and let us know if it does/doesn't work.

-- N

William Herbert

unread,
Oct 13, 2011, 7:37:57 AM10/13/11
to google-visua...@googlegroups.com
As it turns out, there were several things wrong with my work that I stumbled through between when I posted my question last night and this morning.
1) Yes, as you suggested I removed the () from the function being called by setOnLoadCallback
2) There were some errors with my JSON response:
    a) I hadn't added reqId as one of the parameters in my response.  This is kind of ridiculous since when you're using query.send(callback), it overrides any tqx parameter provided with tqx=reqId:0.  I feel that's a little buggy
    b) there were some errors with the format of my output around rows and their cells
3) Rather than trying to make my own data table from scratch, I ended up following http://code.google.com/apis/ajax/playground/?type=visualization#data_source_request and making small changes until I had my data, etc, working as expected.

Thanks for the help!
William

NA

unread,
Oct 13, 2011, 8:52:37 AM10/13/11
to Google Visualization API
I think that the doc indicates you cannot set reqId yourself, but I'm
not positive. This is something the API sets. If you have a page
that makes multiple calls to get data, you'll see the reqID parameter
vary for each call. I assume this is used by the API to determine
which response goes with which request. In that case, it's probably
easier in the long run to let the API handle it.

Glad the other tip helped and that you're up and running!

Reply all
Reply to author
Forward
0 new messages