Namespace: server

mx. server

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
Name Type Description
url string

url from which to fetch the resource

handleAs "text" | "json" | "xml"

format in which to deliver the response

load mx.server~XhrSuccessCallback

function to handle the response

error mx.server~XhrErrorCallback

function to handle errors

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
Name Type Description
request.action string

action to trigger on the server

request.params Object

parameters to pass to the action

request.context mendix/lib/MxContext

context to pass to the action

options.callback mx.server~RequestSuccessCallback

function to handle the result when successful

options.error mx.server~RequestErrorCallback

function to handle errors

Deprecated:
  • since version 7.0, use methods of mx.data instead to access or operate on objects or to invoke microflows.
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.

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.

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 args.handleAs parameter of the original request