Integrated Application Platform › Forums › General › Javascript calling Suneido function
- This topic has 5 replies, 2 voices, and was last updated 10 years, 10 months ago by
amckinlay.
-
AuthorPosts
-
July 14, 2012 at 7:50 pm #731
emilevanpassel
ParticipantI am puzzling to get a Javascript function to call a Suneido function. I have an HTML page with Javascript, the page running in BrowserControl. I can get it to call a Suneido function, but only functions that have no data returning. For example if I want to do a query, how can I make a function return the query result, back to the calling Javascript function?
July 14, 2012 at 8:18 pm #925amckinlay
KeymasterAre you using the suneido:// protocol or running through HttpServer ?
I think you would make an AJAX call. If you are using HttpServer and may have different browsers then you might want to use something like jQuery.ajax
If you are using suneido:// then you can do something like suneido://eval?MyFunc()
If you’re using HttpServer then you would add your function to HttpMap
Your function can then do a query and return the results as JSON or XML.
From the javascript side, this is very similar to what you would do in a normal web app with any other back end.
Is that what you are looking for, or am I misunderstanding?
July 14, 2012 at 9:31 pm #926emilevanpassel
ParticipantI am using the suneido://eval? protocol, but I can’t get it to assign the result to a variable. The only reference in the documentation I see is an example which shows:
function openHelp()
{
document.location="suneido:/eval?OpenBook('HelpBook', 'PageName')";
}This works for calling functions that do not return any result. But when it returns a result, I can’t assign it to a variable. I tried:
var x=suneido:/eval?TestingJS();
but it fails, and when I use:
var x="suneido:/eval?TestingJS();"
it only assigns the string, and no call is made. I’m new to most of Javascript, so I probably got the syntax wrong.
July 14, 2012 at 9:39 pm #927amckinlay
KeymasterYou need to make an AJAX call. There is lots of help on this on the web.
e.g. http://www.w3schools.com/xml/xml_http.asp
Javascript can not call Suneido directly – it can only make requests to web servers, which in this case is Suneido.
July 21, 2012 at 11:58 am #928emilevanpassel
ParticipantI tried the AJAX solution. It is interesting to see what I can do with that. I was wondering how many users can actually be “connected” like this. But this question is more interesting for the other discussion, the one about replacing the cSuneido client with some other type of interface. Having to use HTML, CSS and Javascript on top of Suneido is a bit much, but the flexible number of “connected” users may be an advantage.
July 21, 2012 at 5:42 pm #929amckinlay
KeymasterI like the idea of using the browser for the user interface. But I agree that it is not so good to have to use HTML, CSS, and JavaScript (as well as Suneido).
For multiple connections, it is better to use HttpServer and http:// links instead of the suneido:// protocol. And if you want to handle a lot of connections then jSuneido (the Java version) is better because it is multi-threaded and will take advantage of multiple cores and more memory with 64 bit.
The Eclipse RAP project is interesting – they have implemented SWT on the browser so you can run the same user interface on the desktop or the browser. Google Web Toolkit (GWT) is another interesting approach where they translate Java to JavaScript to run on the browser.
-
AuthorPosts
- You must be logged in to reply to this topic.