Yes, whe know, W3C specs garbaged all the nice IFRAMES that fitted so nicely in our pages. Ajax helped a lot but even if you used Prototye or some other ajax flavoured framework there was soo much work to do; each single link needed an event listener, some tweaking and so on.

After messing up with some application requiring a huge number of ajax calls, I ended up thinking about this little piece of code:

window.onload=function(){
Event.observe(document.body, 'click', function(event) {
    var element = Event.element(event);
    if ('A' == element.tagName){
        if ($(element.target) != undefined){
            new Ajax.Updater(element.target,element.href,
            {method:"post",evalscripts:true})
            Event.stop(event);
            }

        }
    });
}

basically, this 10-line worth trick sets an event listener on every click. If you click on a ‘a’ with a target attribute set up, it starts an Ajax.Updater call on it.
you can of course add GET parameters and feed .php, and of course javascript code is parsed as well..
the complete seed [just a .htm and .php example file added] can be downloaded here

Tags: , ,

One Response to “fast IFRAME-like ajax implementation”

Trackbacks/Pingbacks

  1. fast Ajax reloaded | Working Beta

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>