YUI Library Home

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

Connection Manager: Cross-Domain Transactions with Connection Manager

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.

Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

Copyright © 2011 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings