YUI recommends YUI3.

YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.

This documentation is no longer maintained.

YUI Library Examples: Connection Manager: Cross-Domain Transactions with Connection Manager

Connection Manager: Cross-Domain Transactions with Connection Manager

This example has been deprecated and will no longer be supported. Please note that the XDR functionality of the Connection Manager requires that you host connection.swf on your own servers. YUI 2 is now in maintenance mode, so no future updates are planned and only critical fixes will be considered. For more information, please refer to the following blog posts:

This example demonstrates how to use Connection Manager to make a cross-domain request using the alternate Flash transport. In this example, a request will be made to Yahoo! Pipes, which will respond with JSON data, completing the transaction.

Cross-Domain Requests with Connection Manager

Load the Yahoo Global Object, Connection Manager, and its Event dependency. This example also makes use of the JSON utility.

Initialize the Flash Transport

Before making a cross-domain request, the underlying transport -- connection.swf must be initialized. This is done by calling the transport() on YAHOO.util.Connect, and setting the parameter as the path to the swf, relative to the HTML.

Once the transport has initialized, it will fire xdrReadyEvent. Attach a listener to this event, so we know when the transport is ready for use. Here, the button to send the cross-domain request is disabled until the transport fires xdrReadyEvent.

Configure the Callback Handlers and Make a Cross-Domain Request.

Cross-domain transactions are determined by setting the xdr property on the callback object to true. This instructs Connection Manager to use the alternate transport, initialized earlier, instead of XMLHttpRequest.

In this example, we will create functions to handle success and failure outcomes, and use a global listener to Connection Manager's startEvent to listen for the start of each transaction. Since the response data are JSON, we use the JSON utility to parse it, and use substitute to filter the results.

Copyright © 2013 Yahoo! Inc. All rights reserved.

Privacy Policy - Copyright Policy - Job Openings