Mootools Ajax Example

Mootools Ajax Example

1 Star2 Stars3 Stars4 Stars5 Stars
Posted on February 6, 2009

mootools-ajax

Here’s a quick example of an ajax request with Mootools. the code below is from sandmoose.com. However I have modified it to get the data using the twitter search api.

So the script contains 4 functions, the first function ‘initializeContainer’ makes a new ajax request to our file, in this case ‘twitter.php’. The next function initialises the fade out effect, and tells the function that onComplete to trigger the function ‘updateContainer’. This function puts the data from our file ‘twitter.php’ into the div with and id of contain, once this is done it triggers the function ‘fadeinContainer’ which fades the contents of the div back in.

You need to include the mootools framework, here’s the Google hosted link:

<script src="http://ajax.googleapis.com/ajax/libs/mootools/1.11/mootools-yui-compressed.js" type="text/javascript"><!--mce:0--></script>

The Code:

function initializeContainer() {
	new Ajax('twitter.php', {update:'contain'}).request();
}

function ajaxRequest() {
	$('contain').effect('opacity',{duration:1000, fps:50, onComplete:updateContainer}).start(1,0);
};

function updateContainer() {
	new Ajax('twitter.php', {update:'contain', onComplete:fadeInContainer}).request();
}

function fadeInContainer() {
	$('contain').effect('opacity',{duration:1000, fps:50}).start(0,1);
}

We need to initialise the function onload.

<body onLoad="initializeContainer()">

demodemo


Recent shares

More tutorials from Papermashup
Comments
3 discussions around Mootools Ajax Example
  1. Daniel says:

    Ashley, the link that your provided is not working. Do you have a sample code pertaining to marcus suggestion

  2. marcus says:

    This is great! Is there a way to keep the search results on the page, shifting everything down and fading in the new data (simultaneously dropping the older results)? I’m trying to create a more realtime feed. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

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

Looking for a registry cleaner to speed up your PC and show a full diagnostics?
Faster surfing with Dish Network High Speed Internet

Never miss an update from Papermashup

Get notified about the latest tutorials and downloads.

Subscribe by Email

Get alerts directly into your inbox after each post and stay updated.
Subscribe
OR

Subscribe by RSS

Add our RSS to your feedreader to get regular updates from us.
Subscribe

Get in contact

Please use the form below to get in touch.

About Me

I'm Ashley Ford, Co-founder and Technical Director at Harkable.com London, UK. Previously I worked at InMobi, Spotify and MySpace. My interests include photography and making short videos I'm also an avid F1 fan. I'm always working on side projects. Here are a few: Easy Poll, We Deliver.



What do you specialise in?

I spend a lot of time coding in PHP and MySQL, as well as front end XHTML and CSS. I also specialise in javascript and the jQuery framework as well as being an avid designer. You can find me on dribbble

Interested in advertising?

If you'd like to advertise on Papermashup.com you can find details here Or use the contact link below for further advertising opportunities.

How do I contact you

You can contact me here. and I'm available for consultation, freelance, programming book reviews.

Get on the mailing list

Join over 3000 people who have subscribed to the Papermashup inbox message, and be the first to find out about tutorial, competitions and giveaways.