Llama explained – Javeline Teleport
Step 3 – Making the Ajax call
Now that we have the basic setup we can add AJAX. As I stated at the start of the article, Teleport will do a simple GET or POST request. In this example I’ve chosen for the REST protocol, which does a GET. I don’t have to generate some special format on the server or worst use somekind of complicated server-side framework, I simply have to make a script which output the help.
[snip php-source]code/llama-teleport/step3a.php[/snip]
Teleport is packages into 1 javascript file, which needs to be included in the head HTML page. The zip contains 2 versions: teleport_debug.js and teleport_release.js. The debug version will show an error if you make an error in the teleport definition. The release version doesn’t, but it’s smaller and quite a bit faster. For now we’ll use the debug version, but in real-life it’s advisible to make a symbolic link called teleport.js, so you can easily switch to release version when releasing your project.
[snip html-source]code/llama-teleport/step3b.html[/snip]
We need to define the RPC call using tag in the body of the HTML. The exact syntax of the definition and some more example can be found in the cheat sheet which can also be downloaded.
[snip html-source]code/llama-teleport/step3c.html[/snip]
When the result of the AJAX request is received function llama_setMessage() is called.
[snip js-source]code/llama-teleport/step3d.js[/snip]
The server might have just crashed or the Internet connection of the user might have just gone away or there might have been some other error. Therefor it is necessary to check for an error. If all is ok, we can continue with getting the messagebox using getElementById() and fill innerHTML with the result of the server and display the message box.
Last up is calling the RPC function from the button, replacing the llama_display() with llama_comm.getMessage(MSGID)
[snip html-source]code/llama-teleport/step3e.html[/snip]
Thats all there is to it.
23 Feb 2007 Arnold Daniels





[...] Well, over time several other protocols were created. A group of people doing a lot of javascript based RPC thought it would be nicer to encode the messages using javascript itself. So they created JSON-RPC. With all the hype around web services the PHP developers felt that this was just bloat. Why not just use REST/POST to get the xml. If you want to call the method getUsers. Just call http://www.example.com/rpc.php?func=getUsers and you are done. No extra protocol needed. In particular for non-enterprise solutions this is a very easy way. [...]
Hi!
I did some playing with your code but I can’t seem to get teleport to pass variables around, or at least more than one. I poked and prodded around the ajax.org and the javelin developer site and couldn’t find the right syntax. I get no errors and the help fields work but my little game engine in ajax (Hammurabi, in honor of one of the very first computer games) doesn’t get the form fields value at all.
You can see the llama_msg.php file at
http://ffproject.net/xfer/llama/hamu_llama_msg.txt
BTW, I hope you don’t mind but I named Hammurabi’s prime minister Mr. Llama in your honor
Hi Renmiri,
Great to hear that you are working with TelePort. I am the developer of that library and Arnold asked me to answer your question. If you look at the following code you will see that it works (if I understood your question correctly that is):
var p1 = document.getElementById(”acresp”).value;
var p2 = document.getElementById(”bushelsd”).value;
var p3 = document.getElementById(”landb”).value;
var p4 = document.getElementById(”lands”).value;
llama_comm.getMessage(’newyear’,p1,p2,p3,p4);
When you type Ctrl-g you will get a debug screen in which you can try this code by pasting it in the ‘Javascript console’ section. If this wasn’t the nature of your problem don’t hesitate to ask me about it. If you wish, please join our mailinglist (http://lists.javeline.net/listinfo/internals) so that everybody can benefit from your questions and the answer to them.
Kind Regards,
Ruben Daniëls
Wooohoo!!!!
Got it to work finally! You should use my mods because it shows how to send mre than one value to the php, plus not only hardcoded msgid but form field values as well, allowing you to do form validation just using javeline teleport. Really cool!!!
http://ffproject.net/xfer/llama/index.html
(Try entering negative values!)
your suggestion worked, thanks!!! try it here
http://ffproject.net/xfer/llama/index.html
Download it here
http://ffproject.net/xfer/llama/hammurabi_ajax.zip
I just gotta say I loved Javeline teleport. This will make my life so much easier!!!