Night | Snow

Ajax Request Using MooTools 1.2

Posted on: November 20th, 2009

Tags: , ,

Ajax has become a very important part of the modern web and that won’t change in the near future. The MooTools Framework has made Ajax so simple that even a newbie developer can get their dynamic pages working in no time.

The xhtml part looks like this:

<p>
<a id="start" href="#">Click here</a>
to start Ajax request
</p>
<div id="log">
    <p>Waiting...</p>
</div>

Since version 1.2 you must create an instance of the Request class. We provide our request with the method get (post is certainly provided too), the URL, optional data information, and optional onRequest and onComplete event handlers.

window.addEvent('domready', function() {
        $('start').addEvent('click', function(event) {
        event.stop();
        var url = "ajax.php";
        var req = new Request({    
                method: 'get'
                ,url: url
                ,data: { 'do' : 1 },
                onRequest: function() { },
                onComplete: function(response) {
                        $('log').set('html', response);
                }
        }).send();
      });

And that’s how you made it with the old mootools version 1.1.. but we don’t use that anymore

$('start').addEvent('click', function(e) {
    e = new Event(e).stop();
    var url = "ajax.php";
    new Ajax(url, {method: 'get',update: $('log')
    }).request();
});

News

Martin Fischer said:

Client and partner of simra.ch

Wir können Simon Schärer als kompetenter und zuverlässiger Programmierer höchst weiterempfehlen. Er ist nicht nur ein guter Programmierer, sondern auch ein ausgezeichneter Designer.
Danke Developer’s Island

Follow us on Twitter

favorite

I get asked a lot - which SDK should we use for web programming? I recommend Netbeans

my toolbar

Simra GameMP3 playersubscribe to RSSMy delicious bookmarksFacebookTwitterE-mail

One Response to “Ajax Request Using MooTools 1.2”

RSS Feed Icon  Subscribe to comments follow-up

Dan's Avatar

1

Dan

November 28th, 2009
Permalink this comment

thanks for posting...

0 Trackbacks/Pingbacks

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>

Latest Tweet

loading...