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.RequestThe OpenLayers.Request namespace contains convenience methods for working with XMLHttpRequests.
Constants
DEFAULT_CONFIG{Object} Default configuration for all requests.
Properties
events{OpenLayers.Events} An events object that handles all events on the {OpenLayers.Request} object.
Functions
issueCreate a new XMLHttpRequest object, open it, set any headers, bind a callback to done state, and send any data.
GETSend an HTTP GET request.
POSTSend a POST request.
PUTSend an HTTP PUT request.
DELETESend an HTTP DELETE request.
HEADSend an HTTP HEAD request.
OPTIONSSend an HTTP OPTIONS request.

Constants

DEFAULT_CONFIG

{Object} Default configuration for all requests.

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

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

Functions

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.

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.
issue: function(config)
Create a new XMLHttpRequest object, open it, set any headers, bind a callback to done state, and send any data.
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