[ruby-sajax Top]

Class Sajax

Defined in sajax.rb.

See example_multiply.rb for example.

Class methods:

Sajax.new([params])

Creates an object of Sajax Class. Specify parameters with a Hash to params.

sajax= Sajax.new({:debug_mode => true, :remote_uri => "server.cgi"})
params[:debug_mode]
Specify true to enable debug messages during JavaScript execusion.
params[:remote_uri]
If the script outputting HTML (client) and the script called from JavaScript (server) is separated, specify the server URI here.
params[:request_type]
Specify "GET" or "POST". "POST" should be used if you are sending long requests.
params[:mb_support]
Specify false to disable multi-byte character support. Arguments decoding and encoding conversion is disabled.
params[:kcode]
Specify the character encoding used in Ruby script in $KCODE format. This is the encoding of arguments/return-value of exported functions. $KCODE is used if omitted. UTF-8 is used if $KCODE is also unspecified.

Methods:

export(func_name) { ... }
export(func_name, proc)
export(func_name)

Exports function func_name to be called from JavaScript.

When the function is called, given block or proc.call is executed. How to call the functions from JavaScript? See example_multiply.rb.

Third form is used to declare functions used in the client, in case the client and the server is separated.

handle_client_request()

If it's a function call from JavaScript, executes the function and exits.

Otherwise, does nothing.

javascript

JavaScript source code generated by Sajax.

Embed this in the <script> tag in <head>.

debug_mode
remote_uri
request_type
mb_support
kcode
Each value specified in Sajax.new.