Some days ago I posted part 1a - a short instruction about how to set up a minimal project.
The sample I used to demonstrate that the infrastructure works was as simple as possible and is using a RPC style of Ajax calls to the server. Some topics have not been touched so here they come.
How to get the files
The easiest way to get all the files Ive talked about is to go get them directly from the repository hosted as sourceforge.
http://sourceforge.net/projects/ajaxengine/ is the projects's home page and you can browse the repository directly by using the url http://ajaxengine.svn.sourceforge.net/viewvc/ajaxengine/trunk/.
Here all the development progress will be available as soon as soon as I write about it.
Another possible way to get the files is to use a subversion client for example http://tortoisesvn.tigris.org/ that includes more functionality like getting a copy of all the current files at once, looking into the change log and comparing different versions of the same file.
From time to time the download archives are updated too. You can find them on my site at http://www.mathertel.de/AjaxEngine/#view=Downloads
Calling web services the right way
I have to mention, that this is not the best way of calling a server because synchronous calls may block or freeze the client during the call and the call time may be very long when the network or the server is used a lot. Using asynchronous calls is the answer to that problem and there is simple but great mechanism inside the ajax.js file that makes asynchronous programming quiet easy. Here is just a brief explanation of how to use it. More of the mechanism and it's options can be found in the book Aspects of Ajax.
The typical AJAX scenario follows the following pattern and can be split into 4 separate problems:
- Waiting for an event that will start the Ajax call to the server.
Sometime thats an easy thing to do, because there is a button clicked and we just can attach the initializing code to an event. But sometimes events have to be queued up to avoid a race condition and get wrong answers. - Collecting some data on the client side.
It is often necessary to do this right before you call the server and not in the moment when the call is initiated. - Communication with the server.
That is done by using the client stub that is generated for each SOAP based web service. - Finally using the result from the server.
That must be done, when the data is available and is the typical asynchronous functionality of Ajax.
Many grown-up Ajax implementations are using a JavaScript object that binds the JavaScript functions that all together will solve the scenario and so does the AjaxEngine:
// declare an AJAX action
var action1 = {
// the prepare function collects and returns the data for the server side method.