For Adobe ColdFusion application servers Writing your Client Page

The cf_srs Tag

Firstly, to work with SimpleRemoteScripting you must embed the <cf_srs> tag in the body of your web page. Aside from adding the hidden iframe, this tag will add some JavaScript to your page that describes the Gateway() constructor function. We'll use the constructor function to build our Gateway object.

cf_srs allows one optional parameter. Add the flag trace to make the iframe visible and display a trace window that records the gateway events. This is useful for debugging. Your custom tag will look like this:

<cf_srs trace>

Creating a Gateway

This JavaScript creates a Gateway object:

objGateway = new Gateway(gatewayUrl);

Here, objGateway could be any JavaScript variable name you like. gatewayUrl is the address of the server page that will handle the client requests.

You might place this line of JavaScript in a script block in the head of your web page, or in the onload attribute of your page's body tag like this:

<body onload="myGateway = new Gateway('HTTP://WWW.mywebsite.com/mygateway.cfm');">

Creating a Gateway on an HTTPS page

Microsoft Internet Explorer 6 presents a spurious security warning if an iframe element with no src is added to a secure page. If you are using security, add a blank HTML page to your site and specify the address of the page when you create your gateway:

objGateway = new Gateway(gatewayUrl, blankPageUrl);

For example:

<body onload="myGateway = new Gateway('https://.mywebsite.com/mygateway.cfm', 'https://.mywebsite.com/null.');">

Gateway Methods

Once you have created your gateway, you can invoke the following methods to send requests to the server:

objGateway.setListener( str )
Use this method to specify the name of the function in your web page that will handle the server's response. str is a string representing the function's name. The listener defaults to "alert", which will POP up a JavaScript alert() box containing the server's response. Note that, while ColdFusion is a case-insensitive language, JavaScript is case-sensitive. If you return a structure to your listener function, all the structure keys will be rendered in JavaScript as lower-case.
objGateway.setArguments( obj )
Set the arguments and values to pass to the server. obj is an object literal, which is basically just a set of one or more attribute/value pairs wrapped in curly braces. Here's an example: { name:'Matthew', age:32, country:'NZ' }. You can see that string values need to be wrapped in quotation marks, and colons (:) are used in place of equals signs (=).
objGateway.resetArguments()
Remove all the arguments previously set.
objGateway.request()
Send the request to the server.

Note that you can chain these methods together. For example, it is perfectly acceptable to write:

objGateway.resetArguments().setArguments( { state:'NY' } ).request()

You will typically want to make use of elements' onclick, onchange, onkeyup and similar attributes, so that the methods described above are called when events occur on your page. Your listener function takes the server's response and incorporates the data into your page. Look at the examples to see the various ways listener functions may be written.

World Wide Web
Post Office Protocol
a method of retrieving email from a server.
HyperText Markup Language
The coding language used to create hypertext documents for use on the World Wide Web.
Hypertext Transfer Protocol
The protocol for moving hypertext files across the Internet.