Understanding Ajax Callbacks
An Ajax callback is actually extremely simple. In fact, it is so simple that some people are confused because they somehow expect that there is more to it than there actually is.
Ajax is basically a lightweight way for a browser to exchange a little data with the server without having to refresh the whole page.
The chain of events in an Ajax callback is as follows:
The Ajax callback itself works like this:
The browser sends a message (i.e. data) to the server, and specifies the page (usually the .A5W page in Alpha Anywhere) on the server that will receive the message.
The browser does not wait until a response is received from the server; the user is not prevented from doing something else during the Ajax callback. In other words, the message that is sent to the server is asynchronous — hence the 'A' in Ajax.
On the server side, the message from the browser is received and the page that was specified in the Ajax callback runs. In Alpha Anywhere, this page is just Xbasic code.
It can execute any Xbasic that you want. It can set session variables. It can update records in a database. It can do anything that you would normally do in Xbasic. The important thing to understand about this page is that the data in the message that was sent by the Ajax request is available to it.
This is similar to a page called with parameters. For example, if you had an .A5W page called page1.a5w, and used the url page1.a5w?data1=alpha&data2=beta, then your .A5W page would see two variables, data1 and data2. An Ajax callback that passes data in the callback is doing essentially the same thing, albeit with a different mechanism.
So in summary an Ajax callback looks like this: