Skip to content

Midas JavaScript API

This section contains the full API reference for the midas JavaScript libraries.

For an introduction to writing web pages for midas, see Custom pages: overview. For a first example page, see Hello world! Writing programs in midas.

Each feature also has a "programming" page with examples, such as ODB: programming.

JavaScript runs in the web browser, in custom pages that are served by the midas web server (mhttpd). It talks to midas through mhttpd's JSON-RPC methods, so a page can do almost anything a midas program can: read and write the ODB, start and stop runs, send messages, read history data and more.

The libraries below are served by mhttpd, so a custom page can load them with <script src="...">. You often don't need to write any JavaScript: the HTML widgets in mhttpd.js can display and edit ODB values on their own.

Libraries

Library Contents
mhttpd.js Building custom pages: the standard header and side menu, and HTML widgets (modbvalue, modbcheckbox, gauges, tiles etc.) that display and edit ODB values without any JavaScript
midas.js Calling midas from JavaScript: mjsonrpc_xxx functions for the JSON-RPC methods, such as reading and writing the ODB
controls.js Dialog boxes (dlgAlert(), dlgConfirm(), dlgMessage() etc.) and other controls
filesrw.js A file picker dialog, and reading and writing files on the server (in the experiment's userfiles directory)
mplot.js Plots in custom pages: scatter plots, histograms, bar charts, colour maps and functions
mhistory.js Showing history plots in custom pages
odbbrowser.js The ODB browser and editor used by the built-in ODB page
Deprecated features Older interfaces (<odb> tags and the AJAX interface) that you shouldn't use in new pages

To call a JSON-RPC method that doesn't have its own mjsonrpc_xxx function, use mjsonrpc_call(). The JSON-RPC methods page lists every method and its parameters.

Pages that aren't served by mhttpd

A page served by another web server can also use midas. Load midas.js from mhttpd (e.g. <script src="https://daq.example.com:8443/midas.js">), then call mjsonrpc_set_url() with mhttpd's address before the first mjsonrpc_xxx call:

mjsonrpc_set_url("https://daq.example.com:8443/");

mhttpd allows these cross-site requests. A page opened from a file on your computer (a file:// address) uses https://localhost:8443/ unless you set another address. To connect to mhttpd from other computers, see Web security.