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
|
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
|
Example
define([
"mendix/lib/ConnectionError",
"mendix/lib/ValidationError",
"mendix/lib/Error"
], function(ConnectionError, ValidationError, MxError) {
mx.server.request({
request: {
action: "rollback",
params: {
guid: "2251799813686950"
}
},
options: {
callback: function(state, response) {
console.log("rollback successful");
},
error: function(e) {
if (e instanceof ConnectionError) {
console.log("connection error occured: " + e.message);
} else if (e instanceof ValidationError) {
console.log("validation error occured: " + e.message);
} else if (e instanceof MxError) {
console.log("some other Mendix error occured: " + e.message);
} else {
console.log("some generic error occured: " + e.message);
}
}
}
});
});
Type Definitions
RequestErrorCallback(error)
Error callback for requests.
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | error describing the failure of the request |
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 |
RequestValidationCallback(validations)
Validation callback for requests.
Parameters:
Name | Type | Description |
---|---|---|
validations |
Array.<mendix/lib/ObjectValidation> | validations received for the request |
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 |