Handle server communication.
Methods
(static) get(args)
Fetches a resource from the server using the HTTP GET method.
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
args |
Object |
Properties
|
- Deprecated:
- since version 8.0.0, use the Fetch API instead
Example
mx.server.get({
url: "/data/files/dogs.txt",
handleAs: "text",
load: function(response) {
console.log("dogs", response);
},
error: function(e) {
console.log("failed to retrieve resource");
}
});
(static) getCacheBust() → {string}
Gets the cache bust used to refetch assets after a redeployment.
Returns:
cache bust to append to an URL
- Type
- string
Example
mx.server.getCacheBust(); // Get the cache bust e.g. "635161595264900996"
(static) request(args)
Fires a request to the server.
To fetch objects or invoke microflows, mx.data.get
or mx.data.action
should be used instead.
The args.options.callback
argument is only called when the request was successful.
Its arguments are the state of the request and the response from the server in JSON
format.
When the request fails and args.options.error
was passed, it receives a standard
Javascript Error object.
When args.options.error
was not passed, the mx.onError
function is called on
which you can subscribe using dojo/aspect::after
.
Typically, the UI does this to show an error message for unhandled errors.
Parameters:
Name | Type | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
args |
Object |
Properties
|
- Deprecated:
- since version 7.0, use methods of
mx.data
instead to access or operate on objects or to invoke microflows.
- since version 7.0, use methods of
Example
mx.server.request({
request: {
action: "rollback",
params: {
guid: "2251799813686950"
}
},
options: {
callback: function(state, response) {
console.log("rollback successful");
},
error: function(e) {
console.log("failed to execute command");
}
}
});
Type Definitions
RequestErrorCallback(error)
Error callback for requests.
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | error describing the failure of the request |
- Deprecated:
- since version 7.0, use methods of
mx.data
instead to access or operate on objects or to invoke microflows.
- since version 7.0, use methods of
RequestSuccessCallback(dummy, response)
Success callback for requests.
Parameters:
Name | Type | Description |
---|---|---|
dummy |
string | Dummy parameter that exists for historical reasons. Always set to 'load'. |
response |
Object | response of the request |
- Deprecated:
- since version 7.0, use methods of
mx.data
instead to access or operate on objects or to invoke microflows.
- since version 7.0, use methods of
XhrErrorCallback(error)
Error callback for XHRs.
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | error describing the failure of the request |
XhrSuccessCallback(response)
Success callback for XHRs.
Parameters:
Name | Type | Description |
---|---|---|
response |
string | object | Document | response for the XHR, depending on the |