Send a message to Perspective with javascript AJAX

Hi

If I have the session and page ID, is it possible to send a perspective message with using of AJAX in javascript?

Obviously the system.perspective.sendMessage is using web socket. So if I have session id and page ID it should be possible to send message for specific handler in a view.

I know I can use web dev module but the problem is passing the message to Perspective session and page is hard and make things a little complex.

So I wonder how I can send data with javascript to Perspective page.
Thanks for any idea.

I don’t really understand what you’re asking for. The only way you can run arbitrary JS in Perspective is with a custom module; and a properly constructed custom module can just directly pass things across our message bus. Where are the messages you’re trying to fire coming from, and why can’t you just invoke them through a scripting context directly?

1 Like

Hi Paul

What I’m doing right now is to use some custom web widgets and try to import them in perspective with web dev and iframe.
I use an iframe to request data from web dev by passing data as param of HTTP post method.
Look how it works with char.js in the following example. I pass the start and end date and tagPath as param.
sdfds

Sending data to widget and after that, I prepare data in python endpoint and inject data in HTML or js code string and return to client to show it.


The only problem is to pass user interaction data to perspective. For example when the user clicks or sets a new value on the slider. If I know how to send data to perspective by using a web socket I can have a fully external component without creating a module.

Right now I create another endpoint to update the tag and I can do that by AJAX API in javascript. I just need to pass tagPath address to iframe and after the user change, a value the callback function send new data to ignition. But I need to send data to the prospective component.

I hope you get my idea and understand that creating a custom module is not a simple task for most users. Especially right now that we don’t have any tutorial video and the SDK documentation for perspective.

Sure, but also, most users don't need to embed custom components, and I'd certainly argue that embedding an iframe and setting up Webdev endpoints is also not a simple task...

Why not make a request to (another) Webdev endpoint that just calls system.perspective.sendMessage, if you're already providing the session ID and related params to your iframe?

Why not make a request to (another) Webdev endpoint that just calls system.perspective.sendMessage, if you’re already providing the session ID and related params to your iframe?

Yes as I guess this is only solutions.