Prototype: Ajax.Request

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Airslash
    New Member
    • Nov 2007
    • 221

    #1

    Prototype: Ajax.Request

    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.
    Code:
    function relocateTooltip(_tooltip, _parent, _order) {
        // OffSet variables
        var left = _parent.getWidth();
        var top = 0;
        
        // Check the top offset. reposition if we're the last element.
        if( _order == true) {
            top = $(_parent).getHeight() - _tooltip.getHeight();
        } else {
            top = $(_parent).getHeight();
        }
        
        // position our tooltip witht the calculated values
        _tooltip.clonePosition(_parent, {
            'offsetLeft': left,
            'offsetTop': top
        });
    }
    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.
    Code:
    function loadContent(_tooltip, _url, _caller, _order) {
        new Ajax.Request(_url, {
            method: 'get',
            onSuccess: function(transport) {
                _tooltip.innerHTML = transport.responseText;
    // this part is not working for some reason.
                relocateTooltip(tooltip, _caller, _order);
            },
            onCreate: function(transport) {
                _tooltip.innerHTML = '<img src="/images/tooltip/load_bar.gif" alt="Loading..." />';
                relocateTooltip(tooltip, _caller, _order);
            }
        });
    }
    What I want to know is, how I can make my relocateTooltip call get the parameters from the original function call.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Should it not be _tooltip in place of tooltip?

    Comment

    • Airslash
      New Member
      • Nov 2007
      • 221

      #3
      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

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Well. that's good. Glad you got it sorted.

        Comment

        Working...