Call server side javascript

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

Pnirff
Ebase User
Posts: 21
Joined: Fri Jan 25, 2013 8:36 am

Call server side javascript

#1

Postby Pnirff » Tue Mar 19, 2013 9:14 am

Hello,

I have a client side javascript and need to call a server side javascript from that.
I can not find any documentation and don't know, how to do that.

Thanks a lot
Manfred
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#2

Postby Jon » Tue Mar 19, 2013 10:26 am

Manfred,

The next Ebase release (V4.5) will introduce the ability to call server-side Javascript directly from client Javascript. But until then, you have to use some sort of indirect technique. Which one depends on what you want to achieve. For example:

Invoke a click on something else on your page (button, image etc) using the jquery click() event. If necessary you can set the display:none CSS property. This gives you the ability to trigger a server event which can then run a server script, but you can't get any response back.

To get a response, you need to set up an Integration Service (Ebase web service), and then call this from your client.

Another technique used to supply information to client Javascript is to include form fields and/or tables on the page, again using display:none to make them invisible. Then extract the form field values by navigating the DOM on the client.

Regards
Jon
0 x

Dave
Ebase Staff
Posts: 89
Joined: Mon Sep 10, 2007 11:48 am

#3

Postby Dave » Wed Mar 20, 2013 10:24 am

Another trick for making server-side field values available to client-side javascript is to use && substitution in your HTML++ (Form Properties -> Web Resources).

For example, define a field called F1 on your form, then in the HTML++:

Code: Select all

<script>var F1 = "&&F1";</script>
This will set F1 as a globally (well, globally within the context of your application) accessible javascript variable.

You can extend the idea to pass in text values containing JSON object notation which you simply evaluate to set up the objects on the client side. For example, in server-side javascript:

Code: Select all

fields.EMPLOYEES.value= '&#123; "employees" &#58; &#91;' + 
                        '&#123; "firstName"&#58;"John" , "lastName"&#58;"Doe" &#125;,' +
                        '&#123; "firstName"&#58;"Anna" , "lastName"&#58;"Smith" &#125;,' +
                        '&#123; "firstName"&#58;"Peter" , "lastName"&#58;"Jones" &#125;' + 
                        '&#93;&#125;';
fields.ADDRESSES.value = '&#123;' +
                         '"name"&#58;"John Johnson",' +
                         '"street"&#58;"Oslo West 555",' +
                         '"age"&#58;33,' +
                         '"phone"&#58;"555 1234567"' + 
                         '&#125;';
and then in the HTML++:

Code: Select all

<script>
var employeesObject = eval &#40;"&#40;" + '&&EMPLOYEES' + "&#41;"&#41;;
var addressesObject = eval &#40;"&#40;" + '&&ADDRESSES' + "&#41;"&#41;;
alert&#40;employeesObject.employees&#91;0&#93;.firstName&#41;;
alert&#40;addressesObject.street&#41;;
</script>

NB. You can use HTML++ at the page, form or presentation template level.
0 x

Dave
Ebase Staff
Posts: 89
Joined: Mon Sep 10, 2007 11:48 am

#4

Postby Dave » Tue Mar 26, 2013 10:57 am

Added passing JSON objects.
0 x


Who is online

Users browsing this forum: No registered users and 3 guests