dojo/_base/xhr
Summary
Deprecated. Use dojo/request instead.
Sends an HTTP request with the given method. See also dojo.xhrGet(), xhrPost(), xhrPut() and dojo.xhrDelete() for shortcuts for those HTTP methods. There are also methods for "raw" PUT and POST methods via dojo.rawXhrPut() and dojo.rawXhrPost() respectively.
Usage
xhr(method,args,hasBody);
Parameter | Type | Description |
method | String |
HTTP method to be used, such as GET, POST, PUT, DELETE. Should be uppercase. |
args | Object | |
hasBody | Boolean | Optional
If the request has an HTTP body, then pass true for hasBody. |
Returns: undefined
See the dojo/_base/xhr reference documentation for more information.
Properties
contentHandlers
Defined by: dojo/_base/xhr
A map of available XHR transport handle types. Name matches the handleAs
attribute passed to XHR calls.
Methods
del
(args)
Defined by dojo/_base/xhr
Sends an HTTP DELETE request to the server.
Parameter | Type | Description |
args | Object |
An object with the following properties:
- handleAs (String, optional):
Acceptable values are: text (default), json, json-comment-optional, json-comment-filtered, javascript, xml. See dojo/_base/xhr.contentHandlers
- sync (Boolean, optional):
false is default. Indicates whether the request should be a synchronous (blocking) request.
- headers (Object, optional):
Additional HTTP headers to send in the request.
- failOk (Boolean, optional):
false is default. Indicates whether a request should be allowed to fail (and therefore no console error message in the event of a failure)
- contentType (String|Boolean):
"application/x-www-form-urlencoded" is default. Set to false to prevent a Content-Type header from being sent, or to a string to send a different Content-Type.
- load:
This function will be called on a successful HTTP response code.
- error:
This function will be called when the request fails due to a network or server error, the url is invalid, etc. It will also be called if the load or handle callback throws an exception, unless djConfig.debugAtAllCosts is true. This allows deployed applications to continue to run even when a logic error happens in the callback, while making it easier to troubleshoot while in debug mode.
- handle:
This function will be called at the end of every request, whether or not an error occurs.
- url (String):
URL to server endpoint.
- content (Object, optional):
Contains properties with string values. These properties will be serialized as name1=value2 and passed in the request.
- timeout (Integer, optional):
Milliseconds to wait for the response. If this time passes, the then error callbacks are called.
- form (DOMNode, optional):
DOM node for a form. Used to extract the form values and send to the server.
- preventCache (Boolean, optional):
Default is false. If true, then a "dojo.preventCache" parameter is sent in the request with a value that changes with each request (timestamp). Useful only with GET-type requests.
- rawBody (String, optional):
Sets the raw body for an HTTP request. If this is used, then the content property is ignored. This is mostly useful for HTTP methods that have a body to their requests, like PUT or POST. This property can be used instead of postData and putData for dojo/_base/xhr.rawXhrPost and dojo/_base/xhr.rawXhrPut respectively.
- ioPublish (Boolean, optional):
Set this explicitly to false to prevent publishing of topics related to IO operations. Otherwise, if djConfig.ioPublish is set to true, topics will be published via dojo/topic.publish() for different phases of an IO operation. See dojo/main.__IoPublish for a list of topics that are published.
|
Returns: undefined
fieldToObject
(inputNode)
Defined by dojo/_base/xhr
Serialize a form field to a JavaScript object.
Returns the value encoded in a form field as as a string or an array of strings. Disabled form elements and unchecked radio and checkboxes are skipped. Multi-select elements are returned as an array of string values.
Parameter | Type | Description |
inputNode | DOMNode | String | |
Returns: Object | undefined
Defined by dojo/_base/xhr
Create a serialized JSON string from a form node or string ID identifying the form to serialize
Parameter | Type | Description |
formNode | DOMNode | String | |
prettyPrint | Boolean | Optional |
Returns: String | undefined
Defined by dojo/_base/xhr
Serialize a form node to a JavaScript object.
Returns the values encoded in an HTML form as string properties in an object which it then returns. Disabled form elements, buttons, and other non-value form elements are skipped. Multi-select elements are returned as an array of string values.
Parameter | Type | Description |
formNode | DOMNode | String | |
Returns: object
Examples
Example 1
This form:
<form id="test_form">
<input type="text" name="blah" value="blah">
<input type="text" name="no_value" value="blah" disabled>
<input type="button" name="no_value2" value="blah">
<select type="select" multiple name="multi" size="5">
<option value="blah">blah</option>
<option value="thud" selected>thud</option>
<option value="thonk" selected>thonk</option>
</select>
</form>
yields this object structure as the result of a call to formToObject():
{
blah: "blah",
multi: [
"thud",
"thonk"
]
};
Defined by dojo/_base/xhr
Returns a URL-encoded string representing the form passed as either a node or string ID identifying the form to serialize
Parameter | Type | Description |
formNode | DOMNode | String | |
Returns: String | undefined
get
(args)
Defined by dojo/_base/xhr
Sends an HTTP GET request to the server.
Parameter | Type | Description |
args | Object |
An object with the following properties:
- handleAs (String, optional):
Acceptable values are: text (default), json, json-comment-optional, json-comment-filtered, javascript, xml. See dojo/_base/xhr.contentHandlers
- sync (Boolean, optional):
false is default. Indicates whether the request should be a synchronous (blocking) request.
- headers (Object, optional):
Additional HTTP headers to send in the request.
- failOk (Boolean, optional):
false is default. Indicates whether a request should be allowed to fail (and therefore no console error message in the event of a failure)
- contentType (String|Boolean):
"application/x-www-form-urlencoded" is default. Set to false to prevent a Content-Type header from being sent, or to a string to send a different Content-Type.
- load:
This function will be called on a successful HTTP response code.
- error:
This function will be called when the request fails due to a network or server error, the url is invalid, etc. It will also be called if the load or handle callback throws an exception, unless djConfig.debugAtAllCosts is true. This allows deployed applications to continue to run even when a logic error happens in the callback, while making it easier to troubleshoot while in debug mode.
- handle:
This function will be called at the end of every request, whether or not an error occurs.
- url (String):
URL to server endpoint.
- content (Object, optional):
Contains properties with string values. These properties will be serialized as name1=value2 and passed in the request.
- timeout (Integer, optional):
Milliseconds to wait for the response. If this time passes, the then error callbacks are called.
- form (DOMNode, optional):
DOM node for a form. Used to extract the form values and send to the server.
- preventCache (Boolean, optional):
Default is false. If true, then a "dojo.preventCache" parameter is sent in the request with a value that changes with each request (timestamp). Useful only with GET-type requests.
- rawBody (String, optional):
Sets the raw body for an HTTP request. If this is used, then the content property is ignored. This is mostly useful for HTTP methods that have a body to their requests, like PUT or POST. This property can be used instead of postData and putData for dojo/_base/xhr.rawXhrPost and dojo/_base/xhr.rawXhrPut respectively.
- ioPublish (Boolean, optional):
Set this explicitly to false to prevent publishing of topics related to IO operations. Otherwise, if djConfig.ioPublish is set to true, topics will be published via dojo/topic.publish() for different phases of an IO operation. See dojo/main.__IoPublish for a list of topics that are published.
|
Returns: undefined
objectToQuery
(map)
Defined by dojo/_base/xhr
takes a name/value mapping object and returns a string representing a URL-encoded version of that object.
Parameter | Type | Description |
map | Object | |
Returns: undefined
Examples
Example 1
this object:
{
blah: "blah",
multi: [
"thud",
"thonk"
]
};
yields the following query string:
"blah=blah&multi=thud&multi=thonk"
post
(args)
Defined by dojo/_base/xhr
Sends an HTTP POST request to the server. In addition to the properties listed for the dojo.__XhrArgs type, the following property is allowed:
Parameter | Type | Description |
args | Object |
An object with the following properties:
- handleAs (String, optional):
Acceptable values are: text (default), json, json-comment-optional, json-comment-filtered, javascript, xml. See dojo/_base/xhr.contentHandlers
- sync (Boolean, optional):
false is default. Indicates whether the request should be a synchronous (blocking) request.
- headers (Object, optional):
Additional HTTP headers to send in the request.
- failOk (Boolean, optional):
false is default. Indicates whether a request should be allowed to fail (and therefore no console error message in the event of a failure)
- contentType (String|Boolean):
"application/x-www-form-urlencoded" is default. Set to false to prevent a Content-Type header from being sent, or to a string to send a different Content-Type.
- load:
This function will be called on a successful HTTP response code.
- error:
This function will be called when the request fails due to a network or server error, the url is invalid, etc. It will also be called if the load or handle callback throws an exception, unless djConfig.debugAtAllCosts is true. This allows deployed applications to continue to run even when a logic error happens in the callback, while making it easier to troubleshoot while in debug mode.
- handle:
This function will be called at the end of every request, whether or not an error occurs.
- url (String):
URL to server endpoint.
- content (Object, optional):
Contains properties with string values. These properties will be serialized as name1=value2 and passed in the request.
- timeout (Integer, optional):
Milliseconds to wait for the response. If this time passes, the then error callbacks are called.
- form (DOMNode, optional):
DOM node for a form. Used to extract the form values and send to the server.
- preventCache (Boolean, optional):
Default is false. If true, then a "dojo.preventCache" parameter is sent in the request with a value that changes with each request (timestamp). Useful only with GET-type requests.
- rawBody (String, optional):
Sets the raw body for an HTTP request. If this is used, then the content property is ignored. This is mostly useful for HTTP methods that have a body to their requests, like PUT or POST. This property can be used instead of postData and putData for dojo/_base/xhr.rawXhrPost and dojo/_base/xhr.rawXhrPut respectively.
- ioPublish (Boolean, optional):
Set this explicitly to false to prevent publishing of topics related to IO operations. Otherwise, if djConfig.ioPublish is set to true, topics will be published via dojo/topic.publish() for different phases of an IO operation. See dojo/main.__IoPublish for a list of topics that are published.
|
Returns: undefined
put
(args)
Defined by dojo/_base/xhr
Sends an HTTP PUT request to the server. In addition to the properties listed for the dojo.__XhrArgs type, the following property is allowed:
Parameter | Type | Description |
args | Object |
An object with the following properties:
- handleAs (String, optional):
Acceptable values are: text (default), json, json-comment-optional, json-comment-filtered, javascript, xml. See dojo/_base/xhr.contentHandlers
- sync (Boolean, optional):
false is default. Indicates whether the request should be a synchronous (blocking) request.
- headers (Object, optional):
Additional HTTP headers to send in the request.
- failOk (Boolean, optional):
false is default. Indicates whether a request should be allowed to fail (and therefore no console error message in the event of a failure)
- contentType (String|Boolean):
"application/x-www-form-urlencoded" is default. Set to false to prevent a Content-Type header from being sent, or to a string to send a different Content-Type.
- load:
This function will be called on a successful HTTP response code.
- error:
This function will be called when the request fails due to a network or server error, the url is invalid, etc. It will also be called if the load or handle callback throws an exception, unless djConfig.debugAtAllCosts is true. This allows deployed applications to continue to run even when a logic error happens in the callback, while making it easier to troubleshoot while in debug mode.
- handle:
This function will be called at the end of every request, whether or not an error occurs.
- url (String):
URL to server endpoint.
- content (Object, optional):
Contains properties with string values. These properties will be serialized as name1=value2 and passed in the request.
- timeout (Integer, optional):
Milliseconds to wait for the response. If this time passes, the then error callbacks are called.
- form (DOMNode, optional):
DOM node for a form. Used to extract the form values and send to the server.
- preventCache (Boolean, optional):
Default is false. If true, then a "dojo.preventCache" parameter is sent in the request with a value that changes with each request (timestamp). Useful only with GET-type requests.
- rawBody (String, optional):
Sets the raw body for an HTTP request. If this is used, then the content property is ignored. This is mostly useful for HTTP methods that have a body to their requests, like PUT or POST. This property can be used instead of postData and putData for dojo/_base/xhr.rawXhrPost and dojo/_base/xhr.rawXhrPut respectively.
- ioPublish (Boolean, optional):
Set this explicitly to false to prevent publishing of topics related to IO operations. Otherwise, if djConfig.ioPublish is set to true, topics will be published via dojo/topic.publish() for different phases of an IO operation. See dojo/main.__IoPublish for a list of topics that are published.
|
Returns: undefined
queryToObject
(str)
Defined by dojo/_base/xhr
Create an object representing a de-serialized query section of a URL. Query keys with multiple values are returned in an array.
Parameter | Type | Description |
str | String | |
Returns: object
Examples
Example 1
This string:
"foo=bar&foo=baz&thinger=%20spaces%20=blah&zonk=blarg&"
results in this object structure:
{
foo: [ "bar", "baz" ],
thinger: " spaces =blah",
zonk: "blarg"
}
Note that spaces and other urlencoded entities are correctly handled.