OS JavaSript - Client or Server

OS JavaSript - Client or Server

  

hi there,

I am wondering whether Outsystems's Javascript is a client side or server side?

Sometimes, i put  javascript directly in an expression widget; sometimes i use HttpRequestHandler method RunJavaScript in a server action. Not to mention other javascript variant that is called AJAX.

regards,

IB




If the javascript would be running on the server then the client wouldn't be able to see anything about it.

Hi I Box,

JavaScript is always run client-side, by the browser. You may trigger JavaScript execution from server logic though, it will be executed once the server sends the response back to the browser.

hi Claring,

So, why do we put RunJavaScript in a server action then?

regards,

IB

Jorge Martins wrote:

Hi I Box,

JavaScript is always run client-side, by the browser. You may trigger JavaScript execution from server logic though, it will be executed once the server sends the response back to the browser.


Hi Jorge,

Doesn't it AJAX run on server side?

regards,

IB

I Box wrote:

hi Claring,

So, why do we put RunJavaScript in a server action then?

regards,

IB

RunJavaScript makes the server send a new piece of javascript to the client, after which the client will execute it.

AJAX doesn't run server side either.... ALL javascript runs on the client.

https://www.w3schools.com/xml/ajax_intro.asp


These questions are not really related to Outsystems, but are general to web development, but I'm guessing most people that use outsystems don't really know much about development (since the platform doesn't really require it)

Hi Claring,

Thank you for quick response. Can you give time sequence to whats happen when 

 "RunJavaScript" is called in a server action?

regards,

IB 

Solution

I Box wrote:

Hi Claring,

Thank you for quick response. Can you give time sequence to whats happen when 

 "RunJavaScript" is called in a server action?

regards,

IB 

Hello,

The runjavascript will add in the HTML a script tag that will be executed by the Browser JS Engine after the document is ready.

A simple example of this, is adding a "RunJavascript" action with a JS alert to a screen preparation.

See the result:



As you can see, the script is added to the HTML and a document ready listener will be added.

That's why it's possible to use "RunJavascript" in a screen preparation.

In a screen action, if you use an AJAX with a RunJavascript action, you will receive this as response:

This will be runned by the Engine after receiving the AJAX response.


For the AJAX topic, also called XHR (XMLHttpRequest), is a javascript request, by default asynchronous, but Outsystems uses it as synchronous, waiting for the thread to be completed before sending another request (when in the same browser). This can also be done manually if you personalize your JS code. 

Simple XHR example:


Despite the name, XMLHttpRequest, it can also retrieve any data, not Only XML - Outsystems uses JSON) and can also support different protocols like FTP (not only HTTP(s)).

Just to finish, this is also an AJAX example from Outsystems:


This is what I know for the 9.1 version. 10 version will be explored soon :)

Hope I could help you a little bit more.

Kind regards



Solution

Client side development is done almost exclusively in Javascript. The reason JavaScript is called a client side language is because it runs scripts on your computer (Browser's Engine).

There are a range of server side languages in use on the web today. Ruby, ASP.NET and many others. They are called server side languages because their scripts are run not on your computer, but on the server which hosts the website and sends down the HTML code.


Miguel Sousa wrote:

I Box wrote:

Hi Claring,

Thank you for quick response. Can you give time sequence to whats happen when 

 "RunJavaScript" is called in a server action?

regards,

IB 

Hello,

The runjavascript will add in the HTML a script tag that will be executed by the Browser JS Engine after the document is ready.

A simple example of this, is adding a "RunJavascript" action with a JS alert to a screen preparation.

See the result:



As you can see, the script is added to the HTML and a document ready listener will be added.

That's why it's possible to use "RunJavascript" in a screen preparation.

In a screen action, if you use an AJAX with a RunJavascript action, you will receive this as response:

This will be runned by the Engine after receiving the AJAX response.


For the AJAX topic, also called XHR (XMLHttpRequest), is a javascript request, by default asynchronous, but Outsystems uses it as synchronous, waiting for the thread to be completed before sending another request (when in the same browser). This can also be done manually if you personalize your JS code. 

Simple XHR example:


Despite the name, XMLHttpRequest, it can also retrieve any data, not Only XML - Outsystems uses JSON) and can also support different protocols like FTP (not only HTTP(s)).

Just to finish, this is also an AJAX example from Outsystems:


This is what I know for the 9.1 version. 10 version will be explored soon :)

Hope I could help you a little bit more.

Kind regards



Hi Miguel,

I am still confused about you are saying "

In a screen action, if you use an AJAX with a RunJavascript action, you will receive this as response:".. if i use no AJAX (only Runjavascript) and in click button action (not preparation action), does the script is also run when the event document-is-ready fire?


Second i am interesting with Ajax that is synchronous. What good is it compared with asynchronous one? Is there asynchronous ajax in outsytems? 

Regards,

A

Thank you all,

So I can conclude:

- JavaScript is run by the browser engine :  a client side agent

- The script can be defined somehow using either expression, Runjavascript on server side

- Once exist, the script is run on an event (when the document is ready, etc) in client side

- For OS AJAX, it is synchronize.


best regards,

IB