Namespace: mx

mx

Container of the Mendix client subsystems.

Namespaces

data
meta
parser
server
session
ui

Members

(static) appUrl :string

Root URL of the application, e.g. https://domain.com/mendixapp/.

Type:
  • string

(static) baseUrl :string

URL of the XAS instance, e.g. https://fomain.com/mendixapp/xas/.

Type:
  • string

(static) modulePath :string

The URL of the modules (custom widgets), relative to the dojo directory.

Type:
  • string

(static) version :string

Version of the Mendix platform

Type:
  • string

Methods

(static) addOnLoad(callback)

Adds a function to be called when the client is finished loading. If the client is already loaded, the function will be called immediately.

Parameters:
Name Type Description
callback mx~AddOnLoadCallback

function to be called when the client is finished loading

Example
mx.addOnLoad(function() {
    console.log("You can use client functionality now");
});

(static) login(username, password, onSuccess, onError)

Tries to login using a username and password.

Parameters:
Name Type Description
username string

username to login with

password string

password to login with

onSuccess mx~LoginSuccessCallback

called when the login is successful

onError mx~LoginUnauthorizedCallback

called when the login failed

Example
mx.login("fred", "fred's unguessable password", function() {
    console.log("success");
}, function() {
    console.log("wrong password");
});

(static) logout()

Logs out the user and restarts the client.

Example
mx.logout();   // Restarts the client.

Type Definitions

AddOnLoadCallback()

Callback that can be registered with mx.login

LoginSuccessCallback()

Success callback of mx.login

LoginUnauthorizedCallback()

Unauthorized callback of mx.login

Events

onError

When an error is not handled in the client, the error is passed to onError. Other code can detect these errors by attaching to onError. E.g. the UI code connects to it to show the error to the user.

When client code does not handle an error situation itself, it can pass the error to onError for further handling.

Parameters:
Name Type Description
error Error

The error object describing what went wrong.

Example
aspect.after(mx, "onError", function(error) {
    console.log("Custom error handler:", error);
}, true);

mx.data.create({
    entity: "MyFirstModule.Cat",
    callback: function(obj) {
        console.log("Object created on server");
    },
    error: function(e) {
        // Detect the error but rely on onError() to handle the error further.
        mx.onError(e);
    }
});