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, Map, 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: 5938 $
Author:
Daniel Gredler, Marc Guillemot, Ahmed Ashour, Stuart Begg
See Also:
Safari documentation, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
static int STATE_COMPLETED
          All the data has been received; the complete data is available in responseBody and responseText.
static int STATE_INTERACTIVE
          Some data has been received.
static int STATE_LOADED
          The send() method has been called, but the status and headers are not yet available.
static int STATE_LOADING
          The object has been created, but the send() method has not been called.
static int STATE_UNINITIALIZED
          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
 Object get(String name, net.sourceforge.htmlunit.corejs.javascript.Scriptable start)
          Gets a named property from the object.
 void jsConstructor()
          JavaScript constructor.
 void jsxFunction_abort()
          Cancels the current HTTP request.
 String jsxFunction_getAllResponseHeaders()
          Returns the labels and values of all the HTTP headers.
 String jsxFunction_getResponseHeader(String headerName)
          Retrieves the value of an HTTP header from the response body.
 void jsxFunction_open(String method, Object urlParam, boolean async, String user, String password)
          Assigns the destination URL, method and other optional attributes of a pending request.
 void jsxFunction_overrideMimeType(String mimeType)
          Override the mime type returned by the server (if any).
 void jsxFunction_send(Object content)
          Sends the specified content to the server in an HTTP request and receives the response.
 void jsxFunction_setRequestHeader(String name, String value)
          Sets the specified header to the specified value.
 net.sourceforge.htmlunit.corejs.javascript.Function jsxGet_onerror()
          Returns the event handler that fires on error.
 net.sourceforge.htmlunit.corejs.javascript.Function jsxGet_onload()
          Returns the event handler that fires on load.
 net.sourceforge.htmlunit.corejs.javascript.Function jsxGet_onreadystatechange()
          Returns the event handler that fires on every state change.
 int jsxGet_readyState()
          Returns the current state of the HTTP request.
 String jsxGet_responseText()
          Returns a string version of the data retrieved from the server.
 Object jsxGet_responseXML()
          Returns a DOM-compatible document object version of the data retrieved from the server.
 int jsxGet_status()
          Returns the numeric status returned by the server, such as 404 for "Not Found" or 200 for "OK".
 String jsxGet_statusText()
          Returns the string message accompanying the status code, such as "Not Found" or "OK".
 void jsxSet_onerror(net.sourceforge.htmlunit.corejs.javascript.Function errorHandler)
          Sets the event handler that fires on error.
 void jsxSet_onload(net.sourceforge.htmlunit.corejs.javascript.Function loadHandler)
          Sets the event handler that fires on load.
 void jsxSet_onreadystatechange(net.sourceforge.htmlunit.corejs.javascript.Function stateChangeHandler)
          Sets the event handler that fires on every state change.
 void put(String name, net.sourceforge.htmlunit.corejs.javascript.Scriptable start, Object value)
          
 
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, makeScriptableFor, setCaseSensitive, setDomNode, setDomNode, setHtmlElement
 
Methods inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, clear, containsKey, containsValue, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineOwnProperties, defineOwnProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, entrySet, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypeOf, has, has, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, keySet, preventExtensions, put, put, putAll, putConst, putConstProperty, putProperty, putProperty, redefineProperty, remove, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setParentScope, setPrototype, size, values
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

STATE_UNINITIALIZED

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

See Also:
Constant Field Values

STATE_LOADING

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

See Also:
Constant Field Values

STATE_LOADED

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

See Also:
Constant Field Values

STATE_INTERACTIVE

public static final int STATE_INTERACTIVE
Some data has been received.

See Also:
Constant Field Values

STATE_COMPLETED

public static final int STATE_COMPLETED
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.


jsxGet_onreadystatechange

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

Returns:
the event handler that fires on every state change

jsxSet_onreadystatechange

public void jsxSet_onreadystatechange(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

jsxGet_onload

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

Returns:
the event handler that fires on load

jsxSet_onload

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

Parameters:
loadHandler - the event handler that fires on load

jsxGet_onerror

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

Returns:
the event handler that fires on error

jsxSet_onerror

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

Parameters:
errorHandler - the event handler that fires on error

jsxGet_readyState

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

Returns:
the current state of the HTTP request

jsxGet_responseText

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

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

jsxGet_responseXML

public Object jsxGet_responseXML()
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

jsxGet_status

public int jsxGet_status()
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

jsxGet_statusText

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

Returns:
the string message accompanying the status code

jsxFunction_abort

public void jsxFunction_abort()
Cancels the current HTTP request.


jsxFunction_getAllResponseHeaders

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

Returns:
the labels and values of all the HTTP headers

jsxFunction_getResponseHeader

public String jsxFunction_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

jsxFunction_open

public void jsxFunction_open(String method,
                             Object urlParam,
                             boolean async,
                             String user,
                             String 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

jsxFunction_send

public void jsxFunction_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

jsxFunction_setRequestHeader

public void jsxFunction_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

jsxFunction_overrideMimeType

public void jsxFunction_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

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-2011 Gargoyle Software Inc.. All Rights Reserved.