# OpenLayers.Request

The OpenLayers.Request namespace contains convenience methods for working with XMLHttpRequests. These methods work with a cross-browser W3C compliant OpenLayers.Request.XMLHttpRequest class.

Summary

OpenLayers.Request | The OpenLayers.Request namespace contains convenience methods for working with XMLHttpRequests.
Constants |
DEFAULT_CONFIG | {Object} Default configuration for all requests.
URL_SPLIT_REGEX |
Properties |
events | {OpenLayers.Events} An events object that handles all events on the {OpenLayers.Request} object.
Functions |
makeSameOrigin | Using the specified proxy, returns a same origin url of the provided url.
issue | Create a new XMLHttpRequest object, open it, set any headers, bind a callback to done state, and send any data.
runCallbacks | Calls the complete, success and failure callbacks.
GET | Send an HTTP GET request.
POST | Send a POST request.
PUT | Send an HTTP PUT request.
DELETE | Send an HTTP DELETE request.
HEAD | Send an HTTP HEAD request.
OPTIONS | Send an HTTP OPTIONS request.

### Constants

### DEFAULT_CONFIG

{Object} Default configuration for all requests.

### URL_SPLIT_REGEX

### Properties

### events

{OpenLayers.Events} An events object that handles all events on the {OpenLayers.Request} object.

#### All event listeners will receive an event object with three properties

request | {OpenLayers.Request.XMLHttpRequest} The request object.
config | {Object} The config object sent to the specific request method.
requestUrl | {String} The request url.

#### Supported event types

complete | Triggered when we have a response from the request, if a listener returns false, no further response processing will take place.
success | Triggered when the HTTP response has a success code (200-299).
failure | Triggered when the HTTP response does not have a success code.

### Functions

### makeSameOrigin

> makeSameOrigin: function( | url,
> | proxy | )

Using the specified proxy, returns a same origin url of the provided url.

#### Parameters

url | {String} An arbitrary url proxy {String|Function} The proxy to use to make the provided url a same origin url.

Returns {String} the same origin url. If no proxy is provided, the returned url will be the same as the provided url.

### issue

> issue: function( | config | )

Create a new XMLHttpRequest object, open it, set any headers, bind a callback to done state, and send any data. It is recommended that you use one GET, POST, PUT, DELETE, OPTIONS, or HEAD. This method is only documented to provide detail on the configuration options available to all request methods.

#### Parameters

config | {Object} Object containing properties for configuring the request. Allowed configuration properties are described below. This object is modified and should not be reused.

#### Allowed config properties

method | {String} One of GET, POST, PUT, DELETE, HEAD, or OPTIONS. Default is GET.
url | {String} URL for the request.
async | {Boolean} Open an asynchronous request. Default is true.
user | {String} User for relevant authentication scheme. Set to null to clear current user.
password | {String} Password for relevant authentication scheme. Set to null to clear current password.
proxy | {String} Optional proxy. Defaults to <OpenLayers.ProxyHost>.
params | {Object} Any key:value pairs to be appended to the url as a query string. Assumes url doesn’t already include a query string or hash. Typically, this is only appropriate for GET requests where the query string will be appended to the url. Parameter values that are arrays will be concatenated with a comma (note that this goes against form-encoding) as is done with <OpenLayers.Util.getParameterString>.
headers | {Object} Object with header:value pairs to be set on the request.
data | {String | Document} Optional data to send with the request. Typically, this is only used with POST and PUT requests. Make sure to provide the appropriate “Content-Type” header for your data. For POST and PUT requests, the content type defaults to “application-xml”. If your data is a different content type, or if you are using a different HTTP method, set the “Content-Type” header to match your data type.
callback | {Function} Function to call when request is done. To determine if the request failed, check request.status (200 indicates success).
success | {Function} Optional function to call if request status is in the 200s. This will be called in addition to callback above and would typically only be used as an alternative.
failure | {Function} Optional function to call if request status is not in the 200s. This will be called in addition to callback above and would typically only be used as an alternative.
scope | {Object} If callback is a public method on some object, set the scope to that object.

#### Returns

{XMLHttpRequest} Request object. To abort the request before a response is received, call abort() on the request object.

### runCallbacks

> runCallbacks: function( | options | )

Calls the complete, success and failure callbacks. Application can listen to the “complete” event, have the listener display a confirm window and always return false, and execute OpenLayers.Request.runCallbacks if the user hits “yes” in the confirm window.

#### Parameters

options | {Object} Hash containing request, config and requestUrl keys

### GET

> GET: function( | config | )

Send an HTTP GET request. Additional configuration properties are documented in the issue method, with the method property set to GET.

#### Parameters

config | {Object} Object with properties for configuring the request. See the issue method for documentation of allowed properties. This object is modified and should not be reused.

#### Returns

{XMLHttpRequest} Request object.

### POST

> POST: function( | config | )

Send a POST request. Additional configuration properties are documented in the issue method, with the method property set to POST and “Content-Type” header set to “application/xml”.

#### Parameters

config | {Object} Object with properties for configuring the request. See the issue method for documentation of allowed properties. The default “Content-Type” header will be set to “application-xml” if none is provided. This object is modified and should not be reused.

#### Returns

{XMLHttpRequest} Request object.

### PUT

> PUT: function( | config | )

Send an HTTP PUT request. Additional configuration properties are documented in the issue method, with the method property set to PUT and “Content-Type” header set to “application/xml”.

#### Parameters

config | {Object} Object with properties for configuring the request. See the issue method for documentation of allowed properties. The default “Content-Type” header will be set to “application-xml” if none is provided. This object is modified and should not be reused.

#### Returns

{XMLHttpRequest} Request object.

### DELETE

> DELETE: function( | config | )

Send an HTTP DELETE request. Additional configuration properties are documented in the issue method, with the method property set to DELETE.

#### Parameters

config | {Object} Object with properties for configuring the request. See the issue method for documentation of allowed properties. This object is modified and should not be reused.

#### Returns

{XMLHttpRequest} Request object.

### HEAD

> HEAD: function( | config | )

Send an HTTP HEAD request. Additional configuration properties are documented in the issue method, with the method property set to HEAD.

#### Parameters

config | {Object} Object with properties for configuring the request. See the issue method for documentation of allowed properties. This object is modified and should not be reused.

#### Returns

{XMLHttpRequest} Request object.

### OPTIONS

> OPTIONS: function( | config | )

Send an HTTP OPTIONS request. Additional configuration properties are documented in the issue method, with the method property set to OPTIONS.

#### Parameters

config | {Object} Object with properties for configuring the request. See the issue method for documentation of allowed properties. This object is modified and should not be reused.

#### Returns

{XMLHttpRequest} Request object.

The OpenLayers.Request namespace contains convenience methods for working with XMLHttpRequests.

> makeSameOrigin: function( | url,
> | proxy | )

Using the specified proxy, returns a same origin url of the provided url.

> issue: function( | config | )

Create a new XMLHttpRequest object, open it, set any headers, bind a callback to done state, and send any data.

> runCallbacks: function( | options | )

Calls the complete, success and failure callbacks.

> GET: function( | config | )

Send an HTTP GET request.

> POST: function( | config | )

Send a POST request.

> PUT: function( | config | )

Send an HTTP PUT request.

> DELETE: function( | config | )

Send an HTTP DELETE request.

> HEAD: function( | config | )

Send an HTTP HEAD request.

> OPTIONS: function( | config | )

Send an HTTP OPTIONS request.
Standard-compliant (W3C) cross-browser implementation of the XMLHttpRequest object.
Close