Ok, here's a simple code sample that demonstrates how to load jQuery and use it in a server callback.
The key to understanding what is happening with this, is to understand when the jaxer server instantiates a DOM.
Let's review, the flow from disk to browser is roughly this.
- Get the page from disk
- Spin up the server process and load the page. at this point you have a DOM(1) on the server that has not been passed to the client.
- Complete the page processing (cache functions, run js etc) and serialize the DOM(1) to the client.
- Client gets the page and renders its own DOM(2).
- Client requests callback function
- Jaxer creates environment for callback to execute within (including a DOM(3))
- Callback runs and returns.
NOTE.
DOM(1) exists on the server during the page processing and is then discarded.
DOM(2) exists on the client and can be dynamically changed
DOM(3) exists on the server for the duration of the callback. it has no knowledge of the DOM inside the client browser or the DOM created during initial page processing.
It is important to understand these DOMs are not connected, in any way that would allow changes to be synchronized between them.
So this means that when we do a callback, we have to ensure that the environment is setup the way that we want it. To do this we have the
special 'oncallback()' function that can be defined on a page.
To get the jQuery library to be avaailable during a callback we specify the 'autoload=true' attribute on the src tag, this means that when a callback is made to the page the jaxer instance will load that library into it's DOM before any callback processing takes place.
So when you run this code you should see something like the following in the log
19:06:31 06/05/2008 [ 4676] [INFO] [JS Framework] [framework.] http://127.0.0.1:8000/index.html
19:06:31 06/05/2008 [ 4676] [INFO] [JS Framework] [framework.] Setting up environment for the callback
19:06:31 06/05/2008 [ 4676] [INFO] [JS Framework] [framework.] jQuery already loaded.
19:06:31 06/05/2008 [ 4676] [INFO] [JS Framework] [framework.] first: OK I'm in the callback...
19:06:31 06/05/2008 [ 4676] [INFO] [JS Framework] [framework.] first: ...callback completed
19:06:31 06/05/2008 [ 4676] [INFO] [JS Framework] [framework.] Setting up environment for the callback
19:06:31 06/05/2008 [ 4676] [INFO] [JS Framework] [framework.] jQuery already loaded.
19:06:31 06/05/2008 [ 4676] [INFO] [JS Framework] [framework.] second: OK I'm in the callback...
19:06:31 06/05/2008 [ 4676] [INFO] [JS Framework] [framework.] second: ...callback completed