Mootools 1.1 question

a place to get help

Moderator: 1.1 Moderators

Mootools 1.1 question

Postby dennismonsewicz on Thu Feb 25, 2010 5:58 pm

I am trying to do an AJAX call on the click of a link but for some reason I get no response, no error, no nothing.

  1. <script type="text/javascript" src="/media/system/js/mootools.js"></script>
  2.  
  3. <script type="text/javascript">
  4.     window.addEvent('domready', function() {
  5.         $('click').addEvent('click', function(e) {
  6.             e = new Event(e).stop();
  7.            
  8.             var input = $('test').value;
  9.             var url = "http://www.myurl.com/test.php";
  10.             var postString = 'param=' + input;
  11.            
  12.             new Ajax(url, {
  13.                 method: 'get',
  14.                 data: postString,
  15.                 update: $('log')
  16.             }).request();
  17.             return false;
  18.         });
  19.     });
  20. </script>
  21.  
  22. <input type="text" name="test" id="test" />
  23.  
  24. <p>
  25.     <a href="#" id="click">Click Me!</a>
  26. </p>
  27.  
  28. <div id="log"></div>


Any ideas on why this is not working?
dennismonsewicz
 
Posts: 5
Joined: Thu Feb 25, 2010 5:56 pm

Re: Mootools 1.1 question

Postby dudeinmo on Thu Feb 25, 2010 6:27 pm

Just a note...

For testing purposes, I always use the mootools source at http://ajax.googleapis.com/ajax/libs/mootools/1.1.1/mootools.js - That way I know for a fact that the library is 1.11

I just do this because some think they have one version and actually have another.

And if your not using a form to submit it then you don't need that e in the function on the event or the stop.

  1.    window.addEvent('domready', function() {
  2.         $('click').addEvent('click', function() {
  3.            
  4.             var input = $('test').value;
  5.             var url = "http://www.myurl.com/test.php";
  6.             var postString = 'param=' + input;
  7.            
  8.             new Ajax(url, {
  9.                 method: 'get',
  10.                 data: postString,
  11.                 update: $('log')
  12.             }).request();
  13.             return false;
  14.         });
  15.     });


And if you wanted to get down to brass tacks ... you don't need the Click me section
  1. <p>
  2.     <a href="#" id="click">Click Me!</a>
  3. </p>


just change the addEvent to change and the selector to your test element

  1. $('test').addEvent('change', function() {


Just my observations
"You have to be the change you want to see in the world" - Ghandi
Rob Crowder Designs ( My Site )
MooTools 1.11 Docs
MooTools 1.11 Demos
User avatar
dudeinmo
 
Posts: 10
Joined: Wed Jan 27, 2010 6:56 pm
Location: Sugar Creek, MO

Re: Mootools 1.1 question

Postby dennismonsewicz on Thu Feb 25, 2010 8:44 pm

Hmmm...

Well I tried your suggestion by changing the click event to the change event and the script returned the same results :(

Here is my code now (I added the console.log function to make sure something was happening with the click)

  1.  
  2. <script type="text/javascript">
  3.     window.addEvent('domready', function() {
  4.         $('link').addEvent('click', function() {
  5.            
  6.             console.log("Hello!");
  7.            
  8.             var input = $('test').value;
  9.             var url = "http://www.myrul.com/test.php";
  10.             var postString = 'param=' + input;
  11.            
  12.             new Ajax(url, {
  13.                 method: 'get',
  14.                 data: postString,
  15.                 update: $('log')
  16.             }).request();
  17.            
  18.             return false;
  19.         });
  20.     });
  21. </script>
  22.  
  23. <input type="text" name="test" id="test" />
  24.  
  25. <p>
  26.     <a href="#" id="link">Click Me!</a>
  27. </p>
  28.  
  29. <div id="log"></div>


In Firebug I am not getting any activity posting to another page... any other ideas why this isn't working?
dennismonsewicz
 
Posts: 5
Joined: Thu Feb 25, 2010 5:56 pm

Re: Mootools 1.1 question

Postby dennismonsewicz on Thu Feb 25, 2010 9:15 pm

Ok so I think I have figured out my problem...

I am trying to make an AJAX call to an absolute path and its not working... It works if I make a call to an internal page in my Joomla instance but does not work when I try to make a call outside of the instance...

Any ideas there?
dennismonsewicz
 
Posts: 5
Joined: Thu Feb 25, 2010 5:56 pm

Re: Mootools 1.1 question

Postby dudeinmo on Thu Feb 25, 2010 10:25 pm

well, I do actuall, you should have mentioned the whole joomla thing. I'm at work now, so don't have the code, but all you have to do is use the JBase function to call your link, I just made a ajax app for my joomla/virtuemart install.

Try this:

  1. var url = live_site +"/test.php";

or simply:


I can't remember if this is strictly Joomla or Joomla/Virtuemart

And instead of your console log ... I usuallly just do a alert("hello") or something similar, it pops up if it works, doesn't if it doesn't. I also use firebug with firefox so I can inspect the errors my scripts throw.
"You have to be the change you want to see in the world" - Ghandi
Rob Crowder Designs ( My Site )
MooTools 1.11 Docs
MooTools 1.11 Demos
User avatar
dudeinmo
 
Posts: 10
Joined: Wed Jan 27, 2010 6:56 pm
Location: Sugar Creek, MO

Re: Mootools 1.1 question

Postby dennismonsewicz on Thu Feb 25, 2010 10:46 pm

I am not a big developer inside of the Joomla environment... how would I set the variable of live_site and use it with the Jbase?
dennismonsewicz
 
Posts: 5
Joined: Thu Feb 25, 2010 5:56 pm

Re: Mootools 1.1 question

Postby dudeinmo on Thu Feb 25, 2010 10:51 pm

I would just use the code as it was posted, don't have to set up that live_site or JBase and all of that, joomla should already have that going, in my code for my site, it is the later one :
  1.  
  2. <script type="text/javascript">
  3.     window.addEvent('domready', function() {
  4.         $('link').addEvent('click', function() {
  5.            
  6.             console.log("Hello!");
  7.            
  8.             var input = $('test').value;
  9.             var url = "test.php";
  10.             var postString = 'param=' + input;
  11.            
  12.             new Ajax(url, {
  13.                 method: 'get',
  14.                 data: postString,
  15.                 update: $('log')
  16.             }).request();
  17.            
  18.             return false;
  19.         });
  20.     });
  21. </script>
  22.  
  23. <input type="text" name="test" id="test" />
  24.  
  25. <p>
  26.     <a href="#" id="link">Click Me!</a>
  27. </p>
  28.  
  29. <div id="log"></div>

With nothing before or after the url. But, I'm calling my ajax script from a module, so I have the "/module/rcd_custom/my.php" as the url string. So if your test.php is in the root dir, the code above should work.
"You have to be the change you want to see in the world" - Ghandi
Rob Crowder Designs ( My Site )
MooTools 1.11 Docs
MooTools 1.11 Demos
User avatar
dudeinmo
 
Posts: 10
Joined: Wed Jan 27, 2010 6:56 pm
Location: Sugar Creek, MO

Re: Mootools 1.1 question

Postby dennismonsewicz on Thu Feb 25, 2010 11:15 pm

Well the problem is, is that I am making an AJAX call to another site... So the data I am trying to get back is under another URL... is that even possible?
dennismonsewicz
 
Posts: 5
Joined: Thu Feb 25, 2010 5:56 pm

Re: Mootools 1.1 question

Postby wowenkho on Fri Feb 26, 2010 5:21 am

Cross-domain protocol says no. you may use the Request.JSONP for it, but i don't know if it's in 1.1
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: 1146
Joined: Sat Aug 15, 2009 10:38 am
Location: Antipolo City, Philippines


Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest