Namespace

mx

mx

Container of the Mendix client subsystems.

Namespaces

data
meta
parser
server
session
ui

Members

string

# static appUrl

Root URL from which application is loaded, e.g. https://domain.com/mendixapp/.

string

# static modulePath

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

string

# static remoteUrl

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

string

# static version

Version of the Mendix platform

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 login2(username, password, useAuthToken, 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

useAuthToken boolean

stay logged in until token expires

onSuccess mx~LoginSuccessCallback

called when the login is successful

onError mx~LoginUnauthorizedCallback

called when the login failed

Example
// Example with useAuthToken set to true
mx.login2("fred", "fred's unguessable password", true, 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);
    }
});