JavaScript. At Last.

Working on gpsracr.com this evening, and whipped open my favorite chunk of JS: Prototype. It just gets better all the time. They've added support for automatically executing text that is returned from an Ajax.Request with an appropriate MIME type (like text/javascript), which means you don't even need result handlers. Just dispatch to your URL with whatever parameters you need, and let CF emit back whatever JS should run as a result of the submission (error, failure, success, whatever). Talk about sweet.

Now that might not sound like a big deal, but it really is. I use Fusebox. So all my links are parameterized with XFAs. But XFAs are server-side. Client-side JS (especially static JS in *.js files) can't really access XFAs very well, so URL building is a pain for remoting endpoints and/or hard context switches, But if you're generating the JS server-side….

The specific use case was a login form. I want to "submit" it asynchronously and either display a "denied" message if there's a failure, or forward to the inside of the app if it succeeds. Ordinarily, you'd have to submit the credentials, get some sort of status back from the server, and then use JS to do something with it. Now I can just submit the credentials and let CF emit the JS that I want to execute as a result. I love it.

3 responses to “JavaScript. At Last.”

  1. Rey Bango

    Barney, could you point me to the PT API section that details this functionality?

  2. tanguy

    @Rey

    see

    http://www.prototypejs.org/api/ajax/request

    under the section "Automatic JavaScript response evaluation"

    Other good links for developers interested in prototype:
    http://www.sergiopereira.com/articles/prototype.js.html
    and
    http://thinkweb2.com/projects/prototype-checklist/

    Regs,
    /t