News for hackers. Stuff that matters.
Re:WikiMedia's Geo IP Lookup JSONP call by tybris on Tuesday July 12, 2011 @04:54AM (#2754060)
The approach of dynamically generating a callback script is more robust than pure JSONP. If your URL returns an error (e.g., 404), you immediately notice, instead of waiting for the time-out. These days, my usual approach looks something like this in flight:

    <script type="text/javascript">
        var response = undefined;
    </script>
    <script type="text/javascript" src="...">
       // response = { .... };
    </script>
    <script type="text/javascript">
       _callbacks[1234](response); // response == undefined means error
       response = undefined;       // allow garbage collection
    </script>
    
It's a bit more administration, but I really like not having to worry about dynamic callback names, delayed errors, or non-existent callback functions any more.

There are no comments on this comment yet.