What are your params
? If you’re just executing that code, it’ll fail because params
doesn’t exist in scope. Doing some testing in that example project, even when everything is seemingly done right, it still fails because VisualControl1 doesn’t appear to be available in XojoWeb.controls, which I assume is because there’s no JavaScript class loaded for the object and no actual nodes created.
At any rate, the Gravatar example is better for this. I added the following constant to WebPage1:
Private Const js as String = window.mBujardet = {};
window.mBujardet.sendXojoEvent = function (controlID, eventName, params) {
var controlObject = XojoWeb.getNamedControl(controlID);
if (typeof controlObject != 'undefined' && controlObject != null) {
controlObject.triggerServerEvent(eventName, params, true);
}
}
Then, in WebPage1.Opening:
ExecuteJavaScript( js )
Next, in a button:
ExecuteJavaScript( "mBujardet.sendXojoEvent('" + Gravatar1.ControlID + "', 'test', ['data1', 1, true]);" )
And finally a breakpoint in the Gravatar class’s ExecuteEvent
event I simply added break
. When run, and you click the button, the project will break and you’ll be able to inspect the data sent back.
This isn’t really the right way to do it, but it’ll work. You should be creating a proper JavaScript/TypeScript class and encapsulating everything properly according to the docs and limiting communication. Two-way communication is slow and you should probably be using client-side events for triggering your data submission back to the app for RubberViews.
Note that the params
parameter of sendXojoEvent
accepts a JavaScript object, which is returned to Xojo as a JSONItem. In this example, I’m returning three supported types, a string, a number, and a boolean.