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

How to use XenForo Ajax to auto-update?

Jaxel

Well-known member
#2
So anyone got any ideas? I know how to do this for links outside of XenForo... for instance, this is how I am doing it in XenRio:
Code:
setInterval(function() { updateTwitchTV($form,svalue1); }, 60000);
 
function updateJustinTV($form,svalue1)
{
    var timeNow = new Date().valueOf();
    var query = 'http://api.justin.tv/api/stream/list.json?jsonp=?';
    var args = { 'channel':svalue1 };
 
    $.getJSON(query, args, function(data)
    {
        if (data[0]['channel_count'])
        {
            $form.find('.status').html(data[0]['channel']['status']);
            $form.find('.game').html('<b>'+data[0]['channel']['category']+'</b>');
            $form.find('.viewers b').html(data[0]['channel_count']);
            $form.find('.preview .img').css('background-image', 'url("'+data[0]['channel']['screen_cap_url_medium']+'?t='+timeNow+'")');
        }
        else
        {
            $form.find('.viewers b').html('OFFLINE');
        }
    });
}
But I just don't know how to do this for pages within XenForo.
 

Jaxel

Well-known member
#3
I've got as far as this.... I just don't know how to get "e"
Code:
XenForo.StreamsUpdater = function($form)
{
    setInterval(function()
    {
        $(e.ajaxData.templateHtml).xfInsert('replaceAll', '.streamsSide');
    }, 60000);
}
"e" should contain the noRedirect response from: http://8wayrun.com/streams/streams

How do I tell the javascript to go to that URL and fetch the data?
 

Jaxel

Well-known member
#4
Okay, I got it working for now... through a workaround... seems kinda dumb though...

I wrapped the div I wanted to update in a FORM... then I simply set the interval to automatically submit the form every 60 seconds...

Code:
    XenForo.StreamsUpdater = function($form)
    {
        setInterval(function() { $form.submit(); }, 60000);
 
        $form.bind('AutoValidationComplete', function(e)
        {
            if (e.ajaxData.templateHtml)
            {
                $(e.ajaxData.templateHtml).xfInsert('replaceAll', '.streamsSide');
            }
        });
    }