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

XF 1.3 Can media sites use AJAX callbacks?

Discussion in 'XenForo Questions and Support' started by rhodes, Jun 7, 2014.

  1. rhodes

    rhodes Active Member

    Hello,

    I’ve defined a custom media site:

    mydatadomain.com/pd/*/*/{$id}

    using a php callback function getData(..).

    getData(..) fetches data from an external domain using $id as a parameter. getData(..) finally returns an HTML string (image + link + text). This works pretty good.

    However, I’m asking myself what would happen if mydatadomain.com is not available.
    • My question is if the PHP callback for a media site is called every time a posting is viewed or only once when the posting is created/changed? It would be great if XF could save the HTML string once it is returend from mydatadomain.com

    • Is there any possibilty to use an AJAX callback instead so that my XF forum is not slowed down while waiting for response?

    Regards, rhodes
     
  2. Mike

    Mike XenForo Developer Staff Member

    If you're using an embed callback, it will be hit every time the page is loaded.

    Since you're running arbitrary PHP and returning arbitrary HTML, you could really do whatever you want in terms of caching or an asynchronous callback, but you would need to implement those elements yourself.
     
    Chris D likes this.
  3. Chris D

    Chris D XenForo Developer Staff Member

    Yeah as Mike says, you could implement some of this yourself.

    You may not need a PHP callback. Get your media site to return some simple HTML. You could of course still do the PHP Callback, but ultimately you shouldn't need to return any more than just this:
    HTML:
    <div class="Something" data-id="{$id}"></div>
    Then, you could use a template modification to include some custom JS on each thread view. That JS could perform the AJAX request for you and populate the .Something container with the results fetched based on the contents of the data-id attribute.
     
  4. rhodes

    rhodes Active Member

    @Chris D - very good idea! Thank you. I'll try this.

    What do you personally prefer in this case: a php callback or the ajax solution?
     
  5. Chris D

    Chris D XenForo Developer Staff Member

    For a custom BB code in Xen Media Gallery I implemented an AJAX based solution. It uses a PHP Callback too, but it just parses the BB Code to a simple template object with some basic HTML and then I make the JS do the rest.
     

Share This Page