4 ms·
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, inste
by tybris 15y ago
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.