• 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?

rhodes

Active member
#1
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
 

Mike

XenForo developer
Staff member
#2
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

XenForo developer
Staff member
#3
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.
 

Chris D

XenForo developer
Staff member
#5
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.