Mootools 1.2 syntax question

General Discussion about Mootools 1.2

Moderator: 1.2 Moderators

Mootools 1.2 syntax question

Postby olea_s on Sun Feb 07, 2010 8:41 pm

Hello,

I was writing a script to submit a form via Ajax using Mootools 1.2. Had problems with the first version of script, until I found how to make it work. But I don't understand why the first version doesn't work and the second one works, they look like they do the same thing. Can someone shed the light on this?

In the following scripts, $('task') is the id of the form itself.

Here is the first version of the script, which doesn't send the form to the server, so it just doesn't work:

  1. $('task').addEvent('submit', function(event) {
  2.     event.preventDefault();
  3.     this.send({
  4.         onSuccess: function(response) {
  5.             alert(response);
  6.         }
  7.     });
  8. });


And here is the second version, which looks very similar, but does work perfectly:

  1. $('task').set('send', {
  2.     onSuccess: function(response) {
  3.         alert(response);
  4.     }
  5. }).addEvent('submit', function(event){
  6.     event.preventDefault();
  7.     this.send();
  8. });


What is the difference between these two scripts?

I use Mozilla latest version on Ubuntu.

Thank you very much!
olea_s
 
Posts: 2
Joined: Sat Feb 06, 2010 9:16 am

Re: Mootools 1.2 syntax question

Postby wowenkho on Mon Feb 08, 2010 3:40 am

in MooTools 1.2, you need to change the options using the set() method. you don't modify the options by the time you send() anymore. it is also good practice, if you think about it, that, before sending the ajax request, you've already initialized its options and your only task is to send it alone or with the data required. by the way, take heed on using alert() while dealing with ajax. its modal nature might mess up sync matters. better to use console.log of firebug and inspector instead.
my sword is yours...
http://wowenkho.com

for those who want to talk with me quicker, add me on Yahoo! Messenger through my ID: michaelapeles
User avatar
wowenkho
mootools freak
 
Posts: 1194
Joined: Sat Aug 15, 2009 10:38 am
Location: Antipolo City, Philippines

Re: Mootools 1.2 syntax question

Postby olea_s on Mon Feb 08, 2010 4:08 am

Thank you very much - that completely clarified things for me!
olea_s
 
Posts: 2
Joined: Sat Feb 06, 2010 9:16 am


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest