Here is a simple example of how to easily achieve Ajax-functionality with Domino and Ext.js.
The idea is to, from a page that is opened in a web browser, call a Domino agent asynchronously and in the background to do some work and to provide feedback on it. The page is then updated when the work is done.
1. Download the Ext core (). This is a JavaScript library that among others contains functionality that can be used to achieve Ajax functionality easily.
2. Copy the contents from the JavaScript file 'ext-core.js'
3. In your Lotus Notes database, create a Javascript library named ext-core.js and paste in the copied content from step 2.
4. Create a page with some Pass-Thru HTML.
- A button which when clicked on runs a JavaScript function 'runAjax();'
- A div-tag in where the result from the Ajax query is displayed
<table> <tr><td><input type="button" value="Run" onclick="runAjax();" /></td></tr> <tr><td><div id="results"></div></td></tr> </table> |
5. Add a script tag in the 'HTML Head Content' section of the page to include the JavaScript library to the page.
| <script type='text/javascript' src='ext-core.js'></script> |
6. Define the Javascript function 'runAjax()' in the 'JS Header' section of the page. This function calls an url, in this case a Domino agent, which is run. If the agent was run successfully and the call and response was successful we can decide what to do. Here we update a div on the page with the response from the agent, i.e. what the agent prints.
function runAjax() { Ext.Ajax.request({ url: 'myController?openagent', method: 'GET', success: function(response, opts) { document.getElementById('results').innerHTML = response.responseText; }, failure: function(response, opts) { alert('server-side failure with status code ' + response.status); } });
} |
7. Create the agent 'myController'.
The idea with the agent is to have it run the actual logic and that would be work with Domino data for searching or modifying for example. The agent could just do something with data but also send back information or status to the page that called it. In this example the calling page only runs the agent and the agent only prints a text line as a response or feedback.
Sub Initialize() Print "Foo bar" End Sub |
8. Done! Open the page in the web browser and click the button. The text 'Foo bar' should be displayed shortly in the div.
Note: This does not work in the Notes client, only in a web browser.