1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Another day... another AJAX issue...

Discussion in 'XenForo Development Discussions' started by Jaxel, Feb 28, 2011.

  1. Jaxel

    Jaxel Well-Known Member

    This is my js...
    Code:
    /** @param {jQuery} $ jQuery Object */
    !function($, window, document, _undefined)
    {
    	XenForo.StreamLoader = function($link)
    	{
    		$link.click(function(e)
    		{
    			e.preventDefault();
    
    			XenForo.ajax(
    				$link.attr('href'),
    				{},
    				function(ajaxData, textStatus)
    				{
    					if (ajaxData.templateHtml)
    					{
    						new XenForo.ExtLoader(ajaxData, function()
    						{
    							$(ajaxData.templateHtml).xfInsert('replaceAll', '#streamBox', 'xfShow');
    						});
    					}
    				}
    			);
    		});
    	}
    
    	// *********************************************************************
    
    	XenForo.register('.EWRcharla_Chat div.topCtrl a[href]', 'XenForo.StreamLoader');
    }
    (jQuery, this, document);
    When I click, I get the following error...
    Any idea why?
     
  2. ragtek

    ragtek Guest

    What's your template looking like?
    I think you had the same problem some days ago, because you had no "html tag" around your code.

    bad: foobar
    good: <div id="smafu">foobar</div>

    hth (hope this helps)^^
     
  3. Kier

    Kier XenForo Developer Staff Member

    As Ragtek says, there appears to be nothing wrong with your js, but anything loaded up for inception via .xfInsert() must be surrounded by a single tag.
     
  4. Kier

    Kier XenForo Developer Staff Member

    Also, look into using .hasTemplateHtml() rather than checking ajaxData.templateHtml manually.
     
  5. Jaxel

    Jaxel Well-Known Member

    Yep, it was the single tag issue again... I keep forgetting about that...
    What do you mean? How do I use this?
     
  6. Jaxel

    Jaxel Well-Known Member

    Okay... this is my current JS. You can see how it's being used here:
    http://www.8wayrun.com/chat/
    (click the Show Stream button in the top right control).
    It looks amazing in IE9 and Chrome... looks like ass in Firefox.
    Code:
    /** @param {jQuery} $ jQuery Object */
    !function($, window, document, _undefined)
    {
    	slideSpeed = 1500;
    	slideHeight = 0;
    
    	XenForo.AddStream = function($link)
    	{
    		$link.click(function(e)
    		{
    			e.preventDefault();
    
    			XenForo.ajax(
    				$link.attr('href'),
    				{},
    				function(ajaxData, textStatus)
    				{
    					if (XenForo.hasTemplateHtml(ajaxData))
    					{
    						slideHeight = ajaxData.service_height;
    
    						new XenForo.ExtLoader(ajaxData, function()
    						{
    							$(ajaxData.templateHtml).xfInsert('insertBefore', '#chatBox', 'xfSlideDown', slideSpeed);
    						});
    
    						$('#chatBox').animate({ height: $('#chatBox').height() - slideHeight }, slideSpeed);
    						$('#addStream').hide();
    						$('#remStream').show();
    					}
    				}
    			);
    		});
    	}
    
    	XenForo.RemStream = function($link)
    	{
    		$link.click(function(e)
    		{
    			e.preventDefault();
    
    			$('#chatBox').animate({ height: $('#chatBox').height() + slideHeight }, slideSpeed);
    			$('#addStream').show();
    			$('#remStream').hide();
    			$('#streamBox').xfRemove(null, null, slideSpeed);
    		});
    	}
    
    	// *********************************************************************
    
    	XenForo.register('.EWRcharla_Chat div.topCtrl #addStream', 'XenForo.AddStream');
    	XenForo.register('.EWRcharla_Chat div.topCtrl #remStream', 'XenForo.RemStream');
    }
    (jQuery, this, document);
     
  7. Jaxel

    Jaxel Well-Known Member

    I am having a weird issue with the JS code I posted above...
    You can see an example of it here: http://www.8wayrun.com/chat/

    Click (Show Stream) -> stream boxes will be prependTo #chatBox in a new div called #streamBox...
    Click (Hide Stream) -> stream boxes DONT get deleted, even though it should xfRemove #streamBox...
    Click (Show Stream) -> a second set of stream boxes will appear below the original set...
    Click (Hide Stream) -> the FIRST set of stream boxes will finally disappear...

    Why are the stream boxes not getting removed when they should?
     
  8. Kier

    Kier XenForo Developer Staff Member

    Change this:
    Code:
    if (ajaxData.templateHtml)
    to this
    Code:
    if (XenForo.hasTemplateHtml(ajaxData))
    This is a more robust check, and allows pre-processing to occur should we need to do any in future.
     
  9. Jaxel

    Jaxel Well-Known Member

    Oh... okay... any advice on the post above?

    Nevermind, figured it out... error on my part.
     

Share This Page