
Framework plugins ("flXHRproxy")
[Moderator: Edited to include references to the new Prototype plugin]
I noticed that some people are wondering more about the
jQuery 'flXHRproxy' plugin,
Dojo 'flXHRproxy' plugin, and
Prototype 'flXHRproxy' plugin and how to use them. So, this is an attempt to try and help shed some light on the subject.
flXHR has
several different configuration options which significantly affect its behavior/functionality, such as turning on or off XML response translation or overriding the default policy file location.
So, you may need to use different instance options for different remote server destinations within your application/mashup. For instance, when calling an RSS feed, you may want XML on, but when calling a JSON API, you may want it off to avoid unnecessary XML processing of a non-XML response.
All the framework flXHRproxy plugins have a single primary function called "registerOptions(...)". This function looks and acts the same for all frameworks. It takes two parameters.
The first is the URL (or partial beginning fragment of a URL) to match against. The second parameter is an object (object literal). This object is identical to the object you pass in with named keys for regular flXHR configuration, so any flXHR configuration parameters can be set here. The object will be saved and passed in, as-is, to flXHR for instance configuration.
Whenever you make an Ajax call later in your application, the target URL that you are calling will be matched against all registered URL's. When the first match is found, the plugin will use those configuration options to instantiate flXHR as the transport for that Ajax call.
For Dojo, the DojoX.io | XHR Plugins extension will automatically URL match and select flXHRproxy for transport if the Ajax call warrants it. The same is true for the Prototype flXHRproxy plugin.
For jQuery, however, no automatic transport selection is possible. Instead, you must tell jQuery, either by default Ajax configuration, or per request, that you want to use 'flXHRproxy' as the transport. Once you do that, the URL matching described above will match up and find the appropriate configuration options for each flXHR enabled Ajax call.
So, for jQuery, you have two options for selecting the transport:
One-time default configuration setup: jQuery.ajaxSetup({transport:'flXHRproxy'});
-or-
per Ajax call: jQuery.ajax({..., transport:'flXHRproxy'});