mx.server
Handle server communication.
Methods
request(args)
This method is called to fire 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.connect
. Typically, the UI does this to show an error message for unhandled errors.
Parameters
Name | Type | Description |
---|---|---|
args.request.action | String | The action to trigger on the server. |
args.request.params | Object | Parameters to pass to the action. |
args.request.context | MxContext | Context to pass to the action. |
args.options.unique | Boolean | Whether this request may be merged with an already sent request with the exact same parameters. |
args.options.preventCache | Boolean | Prevent that the response comes from the browser cache. |
args.options.store.caller | Object | The caller instance, on which server instructions can be executed. |
args.options.error | Function | Function to handle errors. |
args.options.callback | Function | Function to handle the result when successful. Arguments are state and response in JSON format. |
args.options.sync | Boolean | Whether the request should be synchronous or asynchronous. |
args.options.onValidation | Function | Function to handle validation feedback. |
args.options.standalone | Boolean | If changes may be sent to the server before executing this action. |
Example
mx.server.request({
request: {
action: "rollback",
params: {
guid: "2251799813686950"
}
},
options: {
callback: function(state, response) {
console.log("rollback successful");
},
error: function(e) {
if (e instanceof mendix.lib.ConnectionError) {
console.log("connection error occured: " + e.message);
} else if (e instanceof mendix.lib.ValidationError) {
console.log("validation error occured: " + e.message);
} else if (e instanceof mendix.lib.Error) {
console.log("some other Mendix error occured: " + e.message);
} else {
console.log("some generic error occured: " + e.message);
}
}
}
});
get(args)
This method is called to fetch a resource from the server. This adds basic connection error handling to dojo.xhrGet
. To get a form, mx.config.getForm should be used instead.
Parameters
Name | Type | Description |
---|---|---|
args.url | String | The url from which to fetch the resource. |
args.load | Function | Function to handle the result. |
args.error | Function | Function to handle errors. |
args.handleAs | String | How to handle the result (text/json/xml). |
For more parameters, and the arguments for the args.load
and args.error
parameters, see dojo.xhrGet documentation.
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");
}
});
getCacheBust()
This method is called to get the cache bust, used to refetch assets after a redeployment.
Returns
Type | Description |
---|---|
String | The cache bust to append to an url. |
Example
mx.server.getCacheBust();
// Get the cache bust e.g. "635161595264900996"