# Yahoo! UI Library

### connection 2.8.0r4

Yahoo! UI Library > connection > YAHOO.util.Connect
Search:
Filters Show Private Show Protected Show Deprecated

## Class YAHOO.util.Connect

The Connection Manager singleton provides methods for creating and managing asynchronous transactions.

### Properties

#### _customEvents - `private static object`

A reference table that maps callback custom events members to its specific event name.

#### _default_form_header - `private static boolean`

The default header used for transactions involving the use of HTML forms.

#### _default_post_header - `private static boolean`

The default header used for POST transactions.

#### _default_xhr_header - `private static boolean`

The default header value for the label "X-Requested-With". This is sent with each transaction, by default, to identify the request as being made by YUI Connection Manager.

#### _has_default_header - `private static boolean`

Determines if custom, default headers are set for each transaction.

#### _has_http_headers - `private static boolean`

Determines if HTTP headers are set.

#### _http_header - `private static object`

Object literal of HTTP header(s)

#### _msxml_progid - `private static array`

Array of MSFT ActiveX ids for XMLHttpRequest.

#### _poll - `private static object`

Collection of polling references to the polling mechanism in handleReadyState.

#### _polling_interval - `private static int`

The polling frequency, in milliseconds, for HandleReadyState. when attempting to determine a transaction's XHR readyState. The default is 50 milliseconds.

#### _timeOut - `private static object`

Queue of timeout values for each transaction callback with a defined timeout value.

#### _transaction_id - `private static int`

A transaction counter that increments the transaction id for each transaction.

#### _use_default_post_header - `private static boolean`

Determines if a default header of Content-Type of 'application/x-www-form-urlencoded' will be added to any client HTTP headers sent for POST transactions.

#### _use_default_xhr_header - `private static boolean`

Determines if a default header of 'X-Requested-With: XMLHttpRequest' will be added to each transaction.

#### abortEvent - `private static CustomEvent`

Custom event that fires when a transaction is successfully aborted.

#### completeEvent - `private static CustomEvent`

Custom event that fires when a transaction response has completed.

#### failureEvent - `private static CustomEvent`

Custom event that fires when handleTransactionResponse() determines a response in the HTTP 4xx/5xx range.

#### startEvent - `private static CustomEvent`

Custom event that fires at the start of a transaction

#### successEvent - `private static CustomEvent`

Custom event that fires when handleTransactionResponse() determines a response in the HTTP 2xx range.

### Methods

#### abort

`static boolean abort ( o , callback , isTimeout )`
Method to terminate a transaction, if it has not reached readyState 4.

Parameters:
  `o <object>` The connection object returned by asyncRequest.
  `callback <object>` User-defined callback object.
  `isTimeout <string>` boolean to indicate if abort resulted from a callback timeout.

Returns: `boolean`

#### asyncRequest

`static object asyncRequest ( method , uri , callback , postData )`
Method for initiating an asynchronous request via the XHR object.

Parameters:
  `method <string>` HTTP transaction method
  `uri <string>` Fully qualified path of resource
  `callback <callback>` User-defined callback function or object
  `postData <string>` POST body

Returns: `object`
  Returns the connection object

#### createExceptionObject

`private static object createExceptionObject ( tId , callbackArg , isAbort )`
If a transaction cannot be completed due to dropped or closed connections, there may be not be enough information to build a full response object. The failure callback will be fired and this specific condition can be identified by a status property value of 0. If an abort was successful, the status property will report a value of -1.

Parameters:
  `tId <int>` The Transaction Id
  `callbackArg <callbackArg>` The user-defined argument or arguments to be passed to the callback
  `isAbort <boolean>` Determines if the exception case is caused by a transaction abort

Returns: `object`

#### createResponseObject

`private static object createResponseObject ( o , callbackArg )`
This method evaluates the server response, creates and returns the results via its properties. Success and failure cases will differ in the response object's property values.

Parameters:
  `o <object>` The connection object
  `callbackArg <callbackArg>` The user-defined argument or arguments to be passed to the callback

Returns: `object`

#### createXhrObject

`private static createXhrObject ( transactionId )`
Instantiates a XMLHttpRequest object and returns an object with two properties: the XMLHttpRequest instance and the transaction id.

Parameters:
  `transactionId <int>` Property containing the transaction id for this transaction.

#### getConnectionObject

`private static object getConnectionObject ( )`
This method is called by asyncRequest to create a valid connection object for the transaction. It also passes a transaction id and increments the transaction id counter.

Returns: `object`

#### handleReadyState

`private static void handleReadyState ( o , callback )`
This method serves as a timer that polls the XHR object's readyState property during a transaction, instead of binding a callback to the onreadystatechange event. Upon readyState 4, handleTransactionResponse will process the response, and the timer will be cleared.

Parameters:
  `o <object>` The connection object
  `callback <callback>` The user-defined callback object

Returns: `void`

#### handleTransactionResponse

`private static void handleTransactionResponse ( o , callback , isAbort )`
This method attempts to interpret the server response and determine whether the transaction was successful, or if an error or exception was encountered.

Parameters:
  `o <object>` The connection object
  `callback <object>` The user-defined callback object
  `isAbort <boolean>` Determines if the transaction was terminated via abort().

Returns: `void`

#### initCustomEvents

`private static void initCustomEvents ( o , callback )`
This method creates and subscribes custom events, specific to each transaction

Parameters:
  `o <object>` The connection object
  `callback <callback>` The user-defined callback object

Returns: `void`

#### initHeader

`static void initHeader ( label , value , isDefault )`
Method that initializes the custom HTTP headers for the each transaction.

Parameters:
  `label <string>` The HTTP header label
  `value <string>` The HTTP header value
  `isDefault <string>` Determines if the specific header is a default header automatically sent with each transaction.

Returns: `void`

#### isCallInProgress

`static boolean isCallInProgress ( o )`
Determines if the transaction is still being processed.

Parameters:
  `o <object>` The connection object returned by asyncRequest

Returns: `boolean`

#### releaseObject

`private static void releaseObject ( o )`
Dereference the XHR instance and the connection object after the transaction is completed.

Parameters:
  `o <object>` The connection object

Returns: `void`

#### resetDefaultHeaders

`static void resetDefaultHeaders ( )`
Resets the default HTTP headers object

Returns: `void`

#### setDefaultPostHeader

`static setDefaultPostHeader ( b )`
Member to override the default POST header.

Parameters:
  `b <boolean>` Set and use default header - true or false .

#### setDefaultXhrHeader

`static setDefaultXhrHeader ( b )`
Member to override the default transaction header..

Parameters:
  `b <boolean>` Set and use default header - true or false .

#### setHeader

`private static void setHeader ( o )`
Accessor that sets the HTTP headers for each transaction.

Parameters:
  `o <object>` The connection object for the transaction.

Returns: `void`

#### setPollingInterval

`static setPollingInterval ( i )`
Member to modify the default polling interval.

Parameters:
  `i <int>` The polling interval in milliseconds.

#### setProgId

`static setProgId ( id )`
Member to add an ActiveX id to the existing xml_progid array. In the event(unlikely) a new ActiveX id is introduced, it can be added without internal code modifications.

Parameters:
  `id <string>` The ActiveX id to be added to initialize the XHR object.

Copyright © 2009 Yahoo! Inc. All rights reserved.