AJAX: Difference between revisions

From MidasWiki
Jump to navigation Jump to search
(The midas documentation has moved to https://midas.triumf.ca/docs/)
Tag: Replaced
 
(64 intermediate revisions by 3 users not shown)
Line 1: Line 1:
= About =
The midas documentation has moved. See [https://midas.triumf.ca/docs/develop/api/javascript/deprecated/#ajax-interface AJAX interface] on the Deprecated web features page for the new documentation about the mhttpd AJAX commands.
 
This page will document the MIDAS AJAX functions accessible through special the mhttpd URLs.
 
= Note on URL encoding =
 
All parameter names and parameter values (?name=value) are passed through urlDecode.
 
* BUG: value of parameter "format" is not passed through urlDecode (git commit db4602dc2ed63674413f92cc92f49f183bd14225, 21 Aug 2013), this is consistent with mhttpd.js which does not urlEncode the values.
 
= jset =
 
* JSONP: no
* parameters:
** ?pnam=<code>xxx</code> - cookie_cpwd to match value of ODB /Custon/Pwd/xxx. How is this supposed to work??? How to use it???
<pre>
      if (*getparam("pnam")) {
        sprintf(ppath, "/Custom/Pwd/%s", getparam("pnam"));
        str[0] = 0;
        db_get_value(hDB, 0, ppath, str, &size, TID_STRING, TRUE);
        if (!equal_ustring(cookie_cpwd, str)) {
            show_text_header();
            rsprintf("Invalid password!");
            return;
        }
      }
</pre>
** ?odb=<code>ODB path</code>
** ?value=<code>data</code>
** ?type=<code>integer</code> - if ODB path does not exist, it is created, with "type" MIDAS TID_xxx data type
** ?len=<code>integer</code> - when ODB path is created, if "len" is not zero, it is made an array of "len" size, with all values set to "value". Except if "type" is TID_STRING, there is no array created, but "len" is used as the ODB string length.
 
* ODB path encoding for arrays:
** /path/array[i] - write array element [i]
** /path/array - write array element [0]
** /path/array[*] - write as many array elements as there are comma-separated values in <code>data</code>
 
* example: TBW
 
= jget =
 
TBW
 
= jcopy =
 
TBW
 
= jkey =
 
* JSONP: no
* parameters:
** ?odb=<code>ODB path</code>
* returns:
<pre>
  if (equal_ustring(getparam("cmd"), "jkey")) {
      show_text_header();
      if (isparam("odb") && db_find_key(hDB, 0, getparam("odb"), &hkey) == DB_SUCCESS) {
        db_get_key(hDB, hkey, &key);
        rsprintf("%s\n", key.name);
        rsprintf("TID_%s\n", rpc_tid_name(key.type));
        rsprintf("%d\n", key.num_values);
        rsprintf("%d\n", key.item_size);
        rsprintf("%d", key.last_written);
      } else
        rsputs("<DB_NO_KEY>");
      return;
  }
</pre>
* example: TBW
 
= jmsg =
 
* JSONP: no
* parameters:
** ?n=<code>number of messages to return</code>
* returns: output of cm_msg_retrieve()
<pre>
  if (equal_ustring(getparam("cmd"), "jmsg")) {
      i = 1;
      if (*getparam("n"))
        i = atoi(getparam("n"));
     
      show_text_header();
      cm_msg_retrieve(i, str, sizeof(str));
      rsputs(str);
      return;
  }
</pre>
* example: TBW
 
= jgenmsg =
 
* JSONP: no
* parameters:
** ?msg=<code>message text</code>
* returns: ???
<pre>
  if (equal_ustring(getparam("cmd"), "jalm")) {
      show_text_header();
      al_get_alarms(str, sizeof(str));
      rsputs(str);
      return;
  }
</pre>
* example: TBW
 
= jalm =
 
* JSONP: no
* parameters: no
* returns: text from al_get_alarms()
 
<pre>
  if (equal_ustring(getparam("cmd"), "jalm")) {
      show_text_header();
      al_get_alarms(str, sizeof(str));
      rsputs(str);
      return;
  }
</pre>
 
* example: TBW

Latest revision as of 22:00, 30 October 2026

The midas documentation has moved. See AJAX interface on the Deprecated web features page for the new documentation about the mhttpd AJAX commands.