-
Notifications
You must be signed in to change notification settings - Fork 4
The Continuation Pipeline
jQuery.continuations provides a pipeline for processing continuations. The pipeline is orchestrated by composable policies.
When an ajax request is processed, jquery.continuations uses a global AJAX handler that is registered via the $.ajaxSetup method. The handler parses the server-side continuation, takes care of any callbacks (explained later), and then hands off the continuation to the processing pipeline.
Often times it's useful to supply a one-off callback for a particular AJAX request but have the pipeline still get invoked. For these scenarios, a continuationSuccess
callback can be supplied to the standard array of $.ajax
options. Here is a simple example:
$.ajax({ url: '/continuation', type: 'get', dataType: 'json', continuationSuccess: function(continuation) { console.log(continuation); } });
Like the success processor, a global error handler is registered via $.ajaxSetup. This handler does one of two things:
- If the content-type of the response is JSON, then it assumes that the server sent a continuation. It then parses it and hands it off to the processing pipeline.
- If the content-type of the response is not JSON, then a client-side continuation is constructed to represent the error (e.g., 301) and handed off to the processing pipeline.
Again, it's often useful to supply one-off handlers for particular requests but still get the power of the conventional processing. For these scenarios, a continuationError
callback can be supplied to the standard array of $.ajax
options. Here is a simple example:
$.ajax({ url: '/continuation', type: 'get', dataType: 'json', continuationError: function(continuation) { console.log(continuation); } });
One of the biggest advantages to a pluggable pipeline is that policies can be shared. jquery.continuations includes lots of defaults that you may want to check out.
There are a handful of useful things to know about that happen during the pipeline. These are all exposed through continuation events.