Embedded Javascript

GoAhead provides an embedded version of Javascript for use in JST pages. As the full Javascript 6 specification is quite a large language, GoAhead's implements a small subset suitable for embedded use. GoAhead Javascript™ is a strict subset of Javascript and implements the essential elements of the language. It also provides the engine for JST pages to enable the easy creation of dynamic web pages.

A standalone product, Embedthis Ejscript™ more fully supports the latest Javascript 6 specification and when used with the Appweb embedded web server is an alternative to GoAhead if you have sufficient memory available.

When GoAhead Javascript is used inside a JST web page, it consists of a script within JST delimiters. The basic format is:

<% function(arguments, ...); %>

Javascript functions are created by the jsSetGlobalFunction. When the function is evaluated, the corresponding C procedure that implements the Javascript function is called.

GoAhead Javascript implements the following Javascript elements:

The following language elements are not implemented:

Javascript scripts can span multiple lines by using "\" as the last character on the preceding line. When used in JST pages, function arguments can contain any query variable defined in either the URL query string or the standard variable set. URL query strings are automatically decoded, and Javascript variables are defined to the decoded query value. For example, to parse the name and address encoded as a query string in a URL, use the following code:

int myAspProcedure(Webs wp, int argc, char **argv) {
    char *name = websGetVar(wp, "name", "undefined");
    char *age = websGetVar(wp, "age", "undefined");
    websWrite(wp, "Name %s, Age %s", name, age);

Javascript procedures are registered by using the websDefineJst API. This publishes a C procedure as a Javascript global function. For example:

extern int outputMyTable(int ejid, Webs wp, int argc, char **argv);
websDefineJst("outputTable", outputMyTable);

The websDefineJst call publishes the Javascript command "outputTable" and links it to the outputMyTable C procedure. When an JST page is requested by the user's browser, any JST Javascript which uses the outputTable command will cause the outputMyTable to be called with the relevant arguments.

© Embedthis Software. All rights reserved.