Properties & methods which are always available within a script.
Lasso also allows global JavaScript functions to be placed in a file named Lasso JSStartup.js (located in the same directory as the Lasso Modules folder). Lasso will execute this file before any other JavaScript code is executed.
The global properties are:
Property |
Description |
---|---|
lasso | This global property provides access to the Lasso object. |
ENCODE_NONE | A read-only property used with the setWriteEncoding function |
ENCODE_URL | A read-only property used with the setWriteEncoding function |
ENCODE_SMART | A read-only property used with the setWriteEncoding function |
ENCODE_BREAKS | A read-only property used with the setWriteEncoding function |
ENCODE_HTML | A read-only property used with the setWriteEncoding function |
The global methods are:
Method |
Description |
---|---|
addResponseHeader | Adds a HTTP header field to the current response. |
deleteResponseHeader | Removes a HTTP header field from the current request. |
flush | Sends any accumulated output data to the client. |
redirect | Redirects the client to the specified URL. |
ssjs_getCGIVariable | Returns the value for a specified server variable. |
encodeURL | Encodes text according for inclusion in a URL. |
encodeSmart | Encodes extended characters into HTMl entities, but does not encode angled brackets. |
encodeBreaks | Encodes line breaks into HTML <br> tags. |
encodeHTML | Encodes all extended characters, including angle brackets, into HTML entities. |
decodeURL | Decodes a URL into plain text. |
setWriteEncoding | Sets the encoding method the write function will use. |
write | Outputs data to the buffer which will be returned to the client. |
Property. This property provides access to the global Lasso object. See Lasso for details.
Method. This method global method allows a single header line to be appended to the HTTP header which will be returned to the client.
addResponseHeader( headerName, headerValue )
headerName is the name of the header field to be added.
headerValue is the value of the header field to be added.
Nothing.
This method can be used to add specific information to the HTTP header which will be returned to the client. For instance, a specific content type for the document or HTTP cookies could be manually added to the header.
New fields are added to the end of the header. Adding a header that already exists does not replace the old header. If you want to replace an existing header field, use the deleteResponseHeader method first, then add the new field and value.
New header fields must be added before calling a method such as flush which sends all the current header information to the client.
addResponseHeader will automatically terminate the new header field with a carriage return/line feed pair. Do not include the carriage return/line feed pair terminator in the header field data.
This example adds a HTTP cookie to the current header.
addResponseHeader( "Set-Cookie", "MyCookie=MyValue" );
Method. Removes a specified HTTP header field if it exists.
deleteResponseHeader( fieldName )
fieldName is the name of the header field to be removed.
Nothing.
This method will remove the specified HTTP header filed from the header is the field is found. This is most useful when used to replace a header field with a new value.
This example will remove the content-type header field.
deleteResponseHeader( "content-type" );
Method. Sends all the currently written output data to the client.
flush()
None.
Nothing.
This method can be used to send partial results to the client. For instance, the HTTP header and any opening HTML HEAD or BODY statements could be sent to the returned at the beginning of the script to provide immediate feedback to the client.
The first time flush is called, the HTTP header will be sent to the client. After this point, any methods which manipulate the HTTP header will be ignored. This includes things such as changing the content type or adding HTTP cookies to the response.
Flush may be called multiple times within a page to provide incremental results from a search or to keep the client connection from timing out during a lengthy request.
This example will loop 100 times and send the value of the loop counter to the client in groups of 5.
for ( var i = 1; i <= 100; ++i ) { write( i, " " ); if ( i % 5 == 0 ) { write( "<BR>" ); flush(); } }
Method. Redirects the client to the specified URL.
redirect( URL )
URL is full Uniform Resource Location to which the client will be redirected
Nothing.
This method will reset the current HTTP header and create a header which will redirect the client to the specified URL. Any data previously in the url will be lost. The new header is not immediately sent to the client, but will be sent when the page is finished processing or the flush method is called.
After redirect is called but before the header is sent to the client, additional header fields may be added or removed using addResponseHeader or deleteResponseHeader.
This example will redirect the client to another site.
redirect( "http://www.blueworld.com/" );
Method. Returns the value for a specified server variable.
ssjs_getCGIVariable( variableName )
variableName is the name of the variable to be returned.
The requested variable, or an empty string if the variable is not found.
This method will return the specified server variable. Valid variable names include the following.
AUTH_TYPE | If authorization was required for the current request, the value "basic" will be returned. |
PATH_INFO | Returns the URL used to call Lasso. If the requested URL was "http://.../path/action.lasso?-...." the value "/path/action.lasso" would be returned. |
PATH_TRANSLATED | Returns an operating system specific full path to the value returned by PATH_INFO. |
QUERY_STRING | Returns the search arguments for the request. |
REMOTE_ADDR | Returns the IP address for the client. |
REMOTE_HOST | Returns the DNS address for the client if available. |
REMOTE_USER | Returns the client's user name if available. |
REQUEST_METHOD | The HTTP method for the request. Either GET or POST. |
SERVER_NAME | The DNS address for the server. |
SERVER_PORT | The port the server is listening on. |
This example will retrieve the client's user name.
var userName = ssjs_getCGIVariable( "REMOTE_USER" );
These methods encode or decode character data according to the specified method.
Note
Character encoding is described in more details in the Lasso Reference Guide.
This example performs URL encoding on a string and displays it.
var s = encodeURL("text=This is a test"); write("http://www.domain.com/action.lasso?", s); => http://www.domain.com/action.lasso?text=This%20is%20a%20test
Method. Sets the character encoding method the write function will use when data is output. All data output by write will be encoded according to the specified method after the encoding method is set. The default encoding for write is ENCODE_NONE.
setWriteEncoding( encodingMethod )
encodingMethod must be on one of the five encoding methods represented by the following global, read-only properties:
ENCODE_NONE
ENCODE_URL
ENCODE_SMART
ENCODE_BREAKS
ENCODE_HTMLNote
Character encoding is described in more details in the Lasso Reference Guide.
Nothing.
This example will set the character encoding method of the write function to HTML.
setWriteEncoding( ENCODE_HTML );
Method. Outputs data to the client.
write( value1 [, value2], ...[, valueN] )
value1 through valueN can be any sort of values that can be coerced into strings.
Nothing.
This method is used to output data to the client. The data is placed in a buffer and is actually sent to the client when the request is finished or the flush method is called.
This example will write a line to the outgoing HTML page.
write( "Hello.", " The current user name is: ", ssjs_getCGIVariable(
"REMOTE_USER" ), "<BR>" );