console.log on page reload?

43 views
Skip to first unread message

Tom Campbell

unread,
Oct 1, 2015, 7:01:14 PM10/1/15
to web2py-users
Working on a single-page app and trying to ensure that only part of the page gets refreshed. Doing some tests using LOAD() that look like this:

file default/new.html:

{{extend 'layout.html'}}
{{=LOAD('default', 'new.load',ajax=True)}}

file default/new.load:

{{if 'message'in globals():}}
<h3>{{=message}}</h3>
{{pass}}
{{=form}}

I added this detection code to web2py_ajax.html:

<script type="text/javascript"><!--
    // These variables are used by the web2py_ajax_init function in web2py_ajax.js (which is loaded below).
    var w2p_ajax_confirm_message = "{{=T('Are you sure you want to delete this object?')}}";
    ...    
 window.onload = function() {
  console.log('RELOADED ' + Date());
};
//--></script>

But the refresh seems to be called every time I choose the action. However, when viewing the console output in Chome I get the hoped-for message starting with:

RELOADED Thu Oct 01 2015 15:36:45 GMT-0700 (PDT)

etc.

What am I doing wrong?

Derek

unread,
Oct 1, 2015, 7:23:28 PM10/1/15
to web2py-users
You don't need that, just do this...

<script type="text/javascript">console.log('loaded ' + date())</script>

Tom Campbell

unread,
Oct 1, 2015, 7:54:33 PM10/1/15
to web2py-users
Thank you, Derek, but I'm still flummoxed. I added this new script tag to web2py_ajax.html:

<script type="text/javascript">console.log('loaded ' + Date.now())</script>

But I'm getting this message even when I use LOAD(). So I'm trying to understand whether I am placing this code in the wrong location or what, because I think it shouldn't be redrawing the page. The XHR record output seems to confirm this.

FWIW the actions are called this way from menu.py:

response.menu = [
        ('Demo', False, '', [
        (T('New task'), False, URL('default', 'new')),
        (T('Show all tasks'), False, URL('default', 'all')),
        ]),
]

Derek

unread,
Nov 5, 2015, 7:18:04 PM11/5/15
to web2py-users
put it in new.html not web2py_ajax
Reply all
Reply to author
Forward
0 new messages