4 ms·
The payload is not JSONP and strikes me as a bit impractical: Geo = { /* object literal */ } I assume this service is meant to be consumed via <script> ta
by crescentfresh 15y ago
The payload is not JSONP and strikes me as a bit impractical:
Geo = { /* object literal */ }
I assume this service is meant to be consumed via <script> tag injection. Without a JSONP-style callback parameter, what are consumers to do, inject-then-poll until a "Geo" object is found in the global scope?
- judofyr 15y ago<script src="http://geoiplookup.wikimedia.org/"></script> <script>geoloaded()</script> </body></html>
- crescentfresh 15y agoD'oh!
- tybris 15y agoThe 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.