By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,759 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,759 IT Pros & Developers. It's quick & easy.

Prototype: Ajax.Request

Airslash
100+
P: 221
Hello,

currently I have 2 functions thatI'm trying to get to work together. Both functions make use of the Prototype library.

The first function moves a div container with ID _tooltip on the screen. This element is positioned absolute and uses the clonePosition to get the coords from its caller (_parent) and then adds an offset to prevent overlap.
This function works.
Expand|Select|Wrap|Line Numbers
  1. function relocateTooltip(_tooltip, _parent, _order) {
  2.     // OffSet variables
  3.     var left = _parent.getWidth();
  4.     var top = 0;
  5.  
  6.     // Check the top offset. reposition if we're the last element.
  7.     if( _order == true) {
  8.         top = $(_parent).getHeight() - _tooltip.getHeight();
  9.     } else {
  10.         top = $(_parent).getHeight();
  11.     }
  12.  
  13.     // position our tooltip witht the calculated values
  14.     _tooltip.clonePosition(_parent, {
  15.         'offsetLeft': left,
  16.         'offsetTop': top
  17.     });
  18. }
  19.  
Now I'm trying to use a second function to fetch data from another page using an AJAX call. The idea behind this is to have a tooltip with live data.
The problem however is that the onSuccess statement never gets called. and the relocation function doesnt work.
If I put everything seperatly then it works, but relocation functions lacks data then.
Expand|Select|Wrap|Line Numbers
  1. function loadContent(_tooltip, _url, _caller, _order) {
  2.     new Ajax.Request(_url, {
  3.         method: 'get',
  4.         onSuccess: function(transport) {
  5.             _tooltip.innerHTML = transport.responseText;
  6. // this part is not working for some reason.
  7.             relocateTooltip(tooltip, _caller, _order);
  8.         },
  9.         onCreate: function(transport) {
  10.             _tooltip.innerHTML = '<img src="/images/tooltip/load_bar.gif" alt="Loading..." />';
  11.             relocateTooltip(tooltip, _caller, _order);
  12.         }
  13.     });
  14. }
  15.  
What I want to know is, how I can make my relocateTooltip call get the parameters from the original function call.
Feb 2 '09 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
Should it not be _tooltip in place of tooltip?
Feb 2 '09 #2

Airslash
100+
P: 221
yeah it's a typo I discovered after posting :p

Also managed to solve the problem. Was collecting the height of the wrong node.Need to drop down 2 levels
Feb 2 '09 #3

acoder
Expert Mod 15k+
P: 16,027
Well. that's good. Glad you got it sorted.
Feb 2 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.