com.gargoylesoftware.htmlunit.javascript.host.xml
Class XMLHttpRequest

java.lang.Object
  extended by net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
      extended by com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
          extended by com.gargoylesoftware.htmlunit.javascript.host.xml.XMLHttpRequest
All Implemented Interfaces:
Serializable, Cloneable, net.sourceforge.htmlunit.corejs.javascript.ConstProperties, net.sourceforge.htmlunit.corejs.javascript.debug.DebuggableObject, net.sourceforge.htmlunit.corejs.javascript.Scriptable

public class XMLHttpRequest
extends SimpleScriptable

A JavaScript object for a XMLHttpRequest.

Version:
$Revision: 8447 $
Author:
Daniel Gredler, Marc Guillemot, Ahmed Ashour, Stuart Begg, Ronald Brill, Sebastian Cato
See Also:
W3C XMLHttpRequest, Safari documentation, Serialized Form

Field Summary
static int STATE_DONE
          All the data has been received; the complete data is available in responseBody and responseText.
static int STATE_HEADERS_RECEIVED
          The send() method has been called, but the status and headers are not yet available.
static int STATE_LOADING
          Some data has been received.
static int STATE_OPENED
          The object has been created, but the send() method has not been called.
static int STATE_UNSENT
          The object has been created, but not initialized (the open() method has not been called).
 
Fields inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 
Fields inherited from interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
XMLHttpRequest()
          Creates a new instance.
XMLHttpRequest(boolean caseSensitiveProperties)
          Creates a new instance.
 
Method Summary
 void abort()
          Cancels the current HTTP request.
 Object get(String name, net.sourceforge.htmlunit.corejs.javascript.Scriptable start)
          Gets a named property from the object.
 String getAllResponseHeaders()
          Returns the labels and values of all the HTTP headers.
 net.sourceforge.htmlunit.corejs.javascript.Function getOnerror()
          Returns the event handler that fires on error.
 net.sourceforge.htmlunit.corejs.javascript.Function getOnload()
          Returns the event handler that fires on load.
 net.sourceforge.htmlunit.corejs.javascript.Function getOnreadystatechange()
          Returns the event handler that fires on every state change.
 int getReadyState()
          Returns the current state of the HTTP request.
 String getResponseHeader(String headerName)
          Retrieves the value of an HTTP header from the response body.
 String getResponseText()
          Returns a string version of the data retrieved from the server.
 Object getResponseXML()
          Returns a DOM-compatible document object version of the data retrieved from the server.
 int getStatus()
          Returns the numeric status returned by the server, such as 404 for "Not Found" or 200 for "OK".
 String getStatusText()
          Returns the string message accompanying the status code, such as "Not Found" or "OK".
 boolean getWithCredentials()
          Returns the "withCredentials" property.
 void jsConstructor()
          JavaScript constructor.
 void open(String method, Object urlParam, boolean async, Object user, Object password)
          Assigns the destination URL, method and other optional attributes of a pending request.
 void overrideMimeType(String mimeType)
          Override the mime type returned by the server (if any).
 void put(String name, net.sourceforge.htmlunit.corejs.javascript.Scriptable start, Object value)
          
 void send(Object content)
          Sends the specified content to the server in an HTTP request and receives the response.
 void setOnerror(net.sourceforge.htmlunit.corejs.javascript.Function errorHandler)
          Sets the event handler that fires on error.
 void setOnload(net.sourceforge.htmlunit.corejs.javascript.Function loadHandler)
          Sets the event handler that fires on load.
 void setOnreadystatechange(net.sourceforge.htmlunit.corejs.javascript.Function stateChangeHandler)
          Sets the event handler that fires on every state change.
 void setRequestHeader(String name, String value)
          Sets the specified header to the specified value.
 void setWithCredentials(boolean withCredentials)
          Sets the "withCredentials" property.
 
Methods inherited from class com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
clone, defineFunctionProperties, defineProperty, equivalentValues, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getTransformerScriptableFor, getWindow, getWindow, getWithPreemption, hasInstance, initParentScope, isReadOnlySettable, makeScriptableFor, setCaseSensitive, setDomNode, setDomNode, setHtmlElement, setParentScope
 
Methods inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setPrototype, size
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_UNSENT

public static final int STATE_UNSENT
The object has been created, but not initialized (the open() method has not been called).

See Also:
Constant Field Values

STATE_OPENED

public static final int STATE_OPENED
The object has been created, but the send() method has not been called.

See Also:
Constant Field Values

STATE_HEADERS_RECEIVED

public static final int STATE_HEADERS_RECEIVED
The send() method has been called, but the status and headers are not yet available.

See Also:
Constant Field Values

STATE_LOADING

public static final int STATE_LOADING
Some data has been received.

See Also:
Constant Field Values

STATE_DONE

public static final int STATE_DONE
All the data has been received; the complete data is available in responseBody and responseText.

See Also:
Constant Field Values
Constructor Detail

XMLHttpRequest

public XMLHttpRequest()
Creates a new instance. JavaScript objects must have a default constructor.


XMLHttpRequest

public XMLHttpRequest(boolean caseSensitiveProperties)
Creates a new instance.

Parameters:
caseSensitiveProperties - if properties and methods are case sensitive
Method Detail

jsConstructor

public void jsConstructor()
JavaScript constructor.


getOnreadystatechange

public net.sourceforge.htmlunit.corejs.javascript.Function getOnreadystatechange()
Returns the event handler that fires on every state change.

Returns:
the event handler that fires on every state change

setOnreadystatechange

public void setOnreadystatechange(net.sourceforge.htmlunit.corejs.javascript.Function stateChangeHandler)
Sets the event handler that fires on every state change.

Parameters:
stateChangeHandler - the event handler that fires on every state change

getOnload

public net.sourceforge.htmlunit.corejs.javascript.Function getOnload()
Returns the event handler that fires on load.

Returns:
the event handler that fires on load

setOnload

public void setOnload(net.sourceforge.htmlunit.corejs.javascript.Function loadHandler)
Sets the event handler that fires on load.

Parameters:
loadHandler - the event handler that fires on load

getOnerror

public net.sourceforge.htmlunit.corejs.javascript.Function getOnerror()
Returns the event handler that fires on error.

Returns:
the event handler that fires on error

setOnerror

public void setOnerror(net.sourceforge.htmlunit.corejs.javascript.Function errorHandler)
Sets the event handler that fires on error.

Parameters:
errorHandler - the event handler that fires on error

getReadyState

public int getReadyState()
Returns the current state of the HTTP request. The possible values are:

Returns:
the current state of the HTTP request

getResponseText

public String getResponseText()
Returns a string version of the data retrieved from the server.

Returns:
a string version of the data retrieved from the server

getResponseXML

public Object getResponseXML()
Returns a DOM-compatible document object version of the data retrieved from the server.

Returns:
a DOM-compatible document object version of the data retrieved from the server

getStatus

public int getStatus()
Returns the numeric status returned by the server, such as 404 for "Not Found" or 200 for "OK".

Returns:
the numeric status returned by the server

getStatusText

public String getStatusText()
Returns the string message accompanying the status code, such as "Not Found" or "OK".

Returns:
the string message accompanying the status code

abort

public void abort()
Cancels the current HTTP request.


getAllResponseHeaders

public String getAllResponseHeaders()
Returns the labels and values of all the HTTP headers.

Returns:
the labels and values of all the HTTP headers

getResponseHeader

public String getResponseHeader(String headerName)
Retrieves the value of an HTTP header from the response body.

Parameters:
headerName - the (case-insensitive) name of the header to retrieve
Returns:
the value of the specified HTTP header

open

public void open(String method,
                 Object urlParam,
                 boolean async,
                 Object user,
                 Object password)
Assigns the destination URL, method and other optional attributes of a pending request.

Parameters:
method - the method to use to send the request to the server (GET, POST, etc)
urlParam - the URL to send the request to
async - Whether or not to send the request to the server asynchronously
user - If authentication is needed for the specified URL, the username to use to authenticate
password - If authentication is needed for the specified URL, the password to use to authenticate

send

public void send(Object content)
Sends the specified content to the server in an HTTP request and receives the response.

Parameters:
content - the body of the message being sent with the request

setRequestHeader

public void setRequestHeader(String name,
                             String value)
Sets the specified header to the specified value. The open method must be called before this method, or an error will occur.

Parameters:
name - the name of the header being set
value - the value of the header being set

overrideMimeType

public void overrideMimeType(String mimeType)
Override the mime type returned by the server (if any). This may be used, for example, to force a stream to be treated and parsed as text/xml, even if the server does not report it as such. This must be done before the send method is invoked.

Parameters:
mimeType - the type used to override that returned by the server (if any)
See Also:
XUL Planet

getWithCredentials

public boolean getWithCredentials()
Returns the "withCredentials" property.

Returns:
the "withCredentials" property

setWithCredentials

public void setWithCredentials(boolean withCredentials)
Sets the "withCredentials" property.

Parameters:
withCredentials - the "withCredentials" property.

get

public Object get(String name,
                  net.sourceforge.htmlunit.corejs.javascript.Scriptable start)
Gets a named property from the object. Normally HtmlUnit objects don't need to overwrite this method as properties are defined on the prototypes from the XML configuration. In some cases where "content" of object has priority compared to the properties consider using utility SimpleScriptable.getWithPreemption(String). For fallback case just implement ScriptableWithFallbackGetter.

Specified by:
get in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
get in class SimpleScriptable

put

public void put(String name,
                net.sourceforge.htmlunit.corejs.javascript.Scriptable start,
                Object value)

Specified by:
put in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
put in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject


Copyright © 2002–2013 Gargoyle Software Inc.. All rights reserved.