CRecordWebSendJson
The
Nearly all messages of the
The reverse process, i.e., handling JSON text sent from the browser, is made possible by the CRecordWebIncomingJson notification.
The message is part of the
The API is located in the plugin NY_
{ "id": "749577d6-2404-49e5-bbbf-04d2a44b539a", "name": "WEB_SEND_JSON ", "description": "Send a json text to the browser.", "slots": [ { "key": "1", "name": "JSON ", "direction": "REQUEST", "mandatory": "true", "type": "STRING", "description": "The json text for the browser." } ] }
Arguments
-
JSON : The JSON text to be sent directly to the Javascript in the browser.
Example
The CRecordWebSetInnerHtml message inserts HTML code into an HTML element. The WebSocket server converts the message into a JSON text, which is then sent to the browser.
{ "cmd": "setInnerHtml", "id": "myDiv", "html": "<p>Hello World!</p>" }
The JavaScript in the browser processes this text by locating the element with the specified ID and then calling the element's setInnerHtml() method.
const element = document.getElementById(id); if (element != null) { element.innerHTML = html; }
Usage with the helper class CWebApisince Version 2.4
The easiest way is to call the corresponding method in the CWebApi class. The use of the class is described there.
mWebApi.sendJson(@NotNull final StringaJson );
Usage as message
The
public void sendJson(@NotNull final CTargetAddressa , @NotNull final StringRemote Skin AddressaJson ) throws CException {// Envelope final CEnvelope env = CEnvelope.forSingleTarget(m );Remote Skin Address// Record final CRecord record =CRecordWebSendJson .create();CRecordWebSendJson .setJson(record,aJson );// send message sendNotification(env, record); }