XenForo.Loader not working, any ideas?

Marcus

Well-known member
PHP:
<a href="{xen:link invoice/test}" class="Loader"
           data-target="#myContainer">Click me...</a>
<div id="myContainer">123456</div>

Once clicking on it, it should display "Hello World". Instead XenForo.Loader is executed and the link is "unlinked" as it should, JSON returns
PHP:
{"templateHtml":"Hello World","css":"","js":"","_visitor_conversationsUnread":"0","_visitor_alertsUnread":"0"}
however nothing happens on the page, #myContainer is not populated with the JSON result. The "123456" is still there.

PHP:
  public function actionTest()
  {
    return $this->responseView(
      'XenForo_ViewPublic_Index',
      'shop_test',
      array()
    );
  }

Template shop_test:
PHP:
Hello World

index.php?invoice/test works great by showing "Hello World". "data-method='replaceAll'" makes the #myContainer disappear, also the unlinking works. So the target is handled, it's just that the template is not rendered there. Do you have any clue what is going wrong? Thanks.


This is Kier's Post for using XenForo.Loader:
 
Last edited:
Is no one using the Loader? It is the most convenient AJAX function for displaying content.
 
I've never used it.

What does your view class look like? Anything in the browser console?
 
There is no view class, the regular view is used then. The browser console shows the json output
PHP:
{"templateHtml":"Hello World","css":"","js":"","_visitor_conversationsUnread":"0","_visitor_alertsUnread":"0"}

It's weird, the function is triggered by class="Loader", but the documentation says "ContentLoader". I mentioned it as bug report: http://xenforo.com/community/thread...-comment-describes-it-as-contentloader.61127/

This function is very powerful as it could display anything anywhere and I ask myself why no one uses it. I did search for that function and there are no returns.
 
I have never used it either. I do use the PreviewTooltip class, and when I first used it I had trouble getting it to work because of 2 things: first I used PreviewToolTip as the class, and second I didn't include the preview_tooltip template that had the required ID that the ajax call looked for. Once I corrected those two mistakes it worked as intended. Just mouse-over one of the pics here to see it work: http://www.icewinddalerp.com/ten-towns/targos/gallaway-trade-depot.42/
 
For reference, the template should be embraced by <html> like "<html>Hello World</html>"

PHP:
  /**
    * Allows a link or input to load content via AJAX and insert it into the DOM.
    * The control element to which this is applied must have href or data-href attributes
    * and a data-target attribute describing a jQuery selector for the element relative to which
    * the content will be inserted.
    *
    * You may optionally provide a data-method attribute to override the default insertion method
    * of 'appendTo'.
    *
    * By default, the control will be unlinked and have its click event unbound after a single use.
    * Specify data-unlink="false" to prevent this default behaviour.
    *
    * Upon successful return of AJAX data, the control element will fire a 'ContentLoaded' event,
    * including ajaxData and textStatus data properties.
    *
    * After template content has been inserted, the control element will fire a 'ContentInserted' event
    * after which the control will be deactivated.
    *
    * @param jQuery a.ContentLoader[href][data-target]
    */
   XenForo.Loader = function($link)
 
Top Bottom