Fixes cross-domain REST model.load() in older browsers via a simple (optional) config update #1304

Open
wants to merge 1 commit into
from

Projects

None yet

4 participants

@chrisrhut

Using ModelSync.REST with IE 8 and 9 was failing when loading with cross-domain GET requests (i.e. the URL of the source data is in a separate domain from the current browser window). Unlike with Y.io(), there is currently no way to pass an XDR config to the underlying AJAX request to fix these errors.

This change simply allows a user to include an XDR object in the "options" parameter of model.load, which is passed through to the underlying Y.io() call. So the documentation for that option applies (i.e. { use: 'native' }).

In IE 8 and 9, this enables the use of the XDomainRequest which supports XDR; additionally this eliminates the extra preflight OPTIONS request in modern CORS-compliant browsers since setting the XDR config object causes Y.io to remove the "X-Requested-With" header.

Chris Hut Enable optional XDR config to be passed into Y.io
This update fixes cross-domain ModelSync.REST load()'s on IE 8 and 9, and
(per the code in Y.io) disables the harmless-but-superfluous preflight OPTIONS
request for XDR requests in modern browsers.
b577ef0
@chrisrhut chrisrhut commented on the diff Oct 11, 2013
src/app/js/model-extensions/model-sync-rest.js
@@ -437,7 +437,9 @@ RESTSync.prototype = {
@param {Number} [options.timeout] The number of milliseconds before the
request will timeout and be aborted. This overrides the default provided
by the static `HTTP_TIMEOUT` property.
- @param {Function} [callback] Called when the sync operation finishes.
+ @param {Object} [options.xdr] XDR config object to pass through to Y.io().
@chrisrhut
chrisrhut Oct 11, 2013

To be honest this documentation is the part I'm most unsure about, since the Y.io documentation on the "xdr" config param is in a state of flux. The current Y.io docs imply that the option is deprecated: http://imgur.com/l1zEIZQ I know that SWF's are gone from YUI (precluding {use:'flash'}), but I believe native XDR (i.e. using XDomainRequest in IE 8/9) will remain supported?

In either case I believe just positioning this as "pass through to Y.io" option will be clear enough to users who need this functionality.

@lsmith
Contributor
lsmith commented Dec 9, 2013

LGTM, but I think @ericf should weigh in.

@clarle clarle was assigned Dec 9, 2013
@clarle clarle was unassigned by jlecomte Mar 13, 2015
@yahoocla

CLA is valid!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment