Wednesday, January 18th, 2006

Moo.ajax: 1.3kb for all your asynchronous needs

Category: Ajax, JavaScript, Library

Valerio Proietti, the creator of Moo.fx, has now created a micro library for Ajax, moo.ajax.

I noticed many of you requested if it would have been possible to use the full prototype, instead of the lite one I provided with the full download of moofx, to use its ajax capabilities along with the effects. Sure you can, but wouldn’t it be cooler if there was a more lightweigt one?

Just to continue my mission in small javascripting, I have arranged this moo.ajax, in just 1.3kb of uncompressed sweetness.

read more for instructions, or download the script. As always, any comments/corrections/suggestions are highly appreciated.

moo.ajax is a very simple ajax class, to be used with prototype.lite from moo.fx. It’s roughly based on the prototype one, so their usage are very similar.

The request

to make any request just call

new ajax(url, options);

The options

  • method: choose either post or get. The default is post.
  • posyBody postBody: if you choose post as method, you can write parameters here.
  • onComplete: a function that will be fired when your request is complete. The request object will be passed as a parameter of the function.
  • update: an dom element or an element’s id. This element will be filled with the request’s responsetext.

An example

This will call my script.php via post, setting as parameter sleep=3. When the request is complete I want an alert with the response text, and I want an element to be updated with the responsetext as well.

new ajax ('sleep.php', {postBody: 'sleep=3', update: $('myelementid'), onComplete: myFunction});
function myFunction(request){
  alert(request.responseText);
}

Posted by Dion Almaer at 12:02 pm
8 Comments

+++--
3.8 rating from 48 votes

8 Comments »

Comments feed TrackBack URI

As the moo-comments are closed, I’ll pester you with my opinion:
I really like moo, and although I don’t know about many other (successful) Ajax libraries, besides a little bit of prototype and dojo, I think moo.fx can play with them.
Now when will I find the time to check out moo.ajax…

Comment by Matthias — January 18, 2006

The beauty of the moo libraries is that they’re so darn simple and super-small. I may not have been using dojo quite right, but my page load times were unacceptable.

Comment by Phil Ridlen — January 18, 2006

[…] Moo.ajax: 1.3kb for all your asynchronous needs […]

Pingback by Llaicky o webu a jiných exotinách » Blog Archive » Moo.ajax: 1.3kb for all your asynchronous needs — January 19, 2006

[…] Ajaxian » Moo.ajax: 1.3kb for all your asynchronous needs […]

Pingback by ТаРаРаМ » Ajaxian » Moo.ajax: 1.3kb for all your asynchronous needs — January 19, 2006

Some one know whi the fade effect don’t work (for me) on IE?. This is the url http://www.purocss.com, the form must fadeout on submit. In firefox work great! :)

Comment by Nicolas — January 19, 2006

[…] http://ajaxian.com/archives/mooajax-13kb-for-all-your-asynchronous-needs […]

Pingback by Project :: penkiblog » 本日書籤 — January 19, 2006

Moo.ajax: 1.3kb for all your asynchronous needs

TrackBack From:http://www.blogjava.net/martinx/archive/2006/01/20/28723.html

Trackback by martin xus — January 19, 2006

Moo.ajax: 1.3kb for all your asynchronous needs

TrackBack From:http://www.blogjava.net/martinx/archive/0001/01/01/28723.html

Trackback by martin xus — January 19, 2006

Leave a comment

You must be logged in to post a comment.