If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!
If You need change timeout interval in Ajax LOAD
 
===================in controller
# -*- coding: utf-8 -*-
TIMES = 20
function = 'change'

def remake_reload_script(timeout):
    return SCRIPT('''
        var jelement = $("#change");
        var element = jelement.get(0);
        var statement = "jQuery('#change').get(0).reload();";
        element.timeout = %s000;
        clearInterval(element.timing); // stop
        element.timing = setInterval(statement, %s000); // start
        ''' % (timeout, timeout))

def change():
    
    r = CAT(
            'example by icreator@mail.ru',
            SCRIPT("""
               if ( ! $('#change').is(':visible')) {
                    $('#change').animate({ height: 'show' }, 1000);
                }
                """)
        )
    
    upd_is = session.UPD_IS
    if upd_is < 3:
        timeout = 5
    elif upd_is < 6:
        timeout = 20
    else:
        timeout = 100
    
    upd_is += 1
    session.UPD_IS = upd_is
    r += remake_reload_script(timeout)
    if upd_is < TIMES:
        content = CAT(
                  T('Auto-updating each %s sec') % timeout, ', ',
                  T('times left'), ': ', TIMES - upd_is)
    else:
        content = CAT(T('Auto-updating is stoped. For start auto-updating please reload the page.'))

    r += DIV(content)
    if upd_is > 1: r += DIV( request.args(0))
    if upd_is > 2: r += DIV( request.vars.get('v'))
    if upd_is > 3: r += DIV( T('it is very slow now'))
    
    return r

def index():
    r = CAT()
    r += DIV('LOAD with changed interval')
    session.UPD_IS = 0
    controller = 'interval'
    r += LOAD(controller, function, args=['hello'], vars={'v':'WORLD'}, ajax=True,
                times = TIMES, timeout=1000,
                target=function,
                _style='display:none;',
                _class='container',
            )
    return dict(r=r)
=============== in view index.html:
{{extend 'layout.html'}}
{{=r}}
 

Related slices

Comments (0)


Hosting graciously provided by:
Python Anywhere