Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

leo (5366)

leo
  (email not shown publicly)

Journal of leo (5366)

Tuesday September 05, 2006
05:41 PM

Parrot can do AJAX too!

[ #30902 ]

Above subject is shamelessy stolen from Jonathan, who has used it on IRC. Anyway, I got bored by doing my presentations with

$ ./parrot slpod.imc yapc.pod

... or some such. I wrote the predecessor of that at YAPC::EU::2003 during lunch break and the slides at dinner (no, that isn't a joke) and it caused a lot of fun at these days.

But in recent times all has to be AJAX, hasn't it? Alas, I started hacking examples/io/httpd.pir to support a CGI GET request, which is invoking Parrot subroutines, and put together 60 lines of JavaScript dealing mainly with keyboard requests to navigate between slide pieces and to send XMLHttpRequests. The XML thingy is totally optional, don't be afraid, plain text messages or html snippets are working fine too - and that's what the next slide presentation program will use.

Given that your GET request delivers a valid HTML snippet, and you got e.g. <div id="answer"></div> on your html page, then all you need to fill this with contents is mainly this JavaScript two-liner:

var x = document.getElementById('answer');
x.innerHTML = req.responseText;

That's almost it. I'll put together a working example in the parrot repo during the next days.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • If I were cruel, I would suggest that someone write an HTTP parser with PGE, but I'll wait until the new version of TGE comes out. That ought to make it substantially easier.

  • The XML thingy is totally optional
    It sure is. The whole "XMLHttpRequest" name is a misnomer, plain "HttpRequest" would have been more truthful.

    Even Wikipedia uses something very close to Sajax [modernmethod.com], internally: plain text, a leading "+" indicating success, a "-" indicating error.