[web2py] Re: I am trying to change the background image every 5 seconds like this but this doesn't seem to work?

2016-06-14 Thread Anthony
The URL is in Javascript. In: var baseUrl = '{{=URL('static', 'images')}}' the part in curly braces is Python, which gets executed on the server before the page is sent to the browser. In the browser, you will end up with HTML that looks like: var baseUrl = '/yourapp/static/images'; That's a

[web2py] Re: I am trying to change the background image every 5 seconds like this but this doesn't seem to work?

2016-06-14 Thread Emmanuel Dsouza
But how do I opened a random d.jpg through Javascript to a URL that is in Python? On Tuesday, June 14, 2016 at 5:14:13 PM UTC+5:30, Anthony wrote: > > No, you're still attempting to run Python code in Javascript. You must > write actual Javascript code -- no Python. You should only be using

[web2py] Re: I am trying to change the background image every 5 seconds like this but this doesn't seem to work?

2016-06-14 Thread Anthony
No, you're still attempting to run Python code in Javascript. You must write actual Javascript code -- no Python. You should only be using Python to create the base URL -- for example: var baseUrl = '{{=URL('static', 'images')}}'; [everything else is Javascript] Anthony On Tuesday,

[web2py] Re: I am trying to change the background image every 5 seconds like this but this doesn't seem to work?

2016-06-14 Thread Emmanuel Dsouza
Thank you Anthony but still it is not going through! Could you check why: {{extend 'layout.html'}} window.setInterval(function(){ {{i=URL('static','images/%d.jpg' %(randint(0,2)))}} document.body.style.background = url("{{=i}}"); }, 5000); Even this one doesn't work: {{extend

[web2py] Re: I am trying to change the background image every 5 seconds like this but this doesn't seem to work?

2016-06-14 Thread Anthony
Actually, in this case, you don't really need to bother with Ajax. Instead, just implement the random integer generation in Javascript and use the random integer to generate the URL in Javascript. For future reference, though, the third argument to the ajax() function can be ":eval" (which

[web2py] Re: I am trying to change the background image every 5 seconds like this but this doesn't seem to work?

2016-06-13 Thread Emmanuel Dsouza
I was obviously waiting for your reply only. Ok Anthony I got what you said. But how do I get a variable through an ajax call? Ajax only updates a tag id, right? How do I edit this to make it work? in controller: def index(): return locals() in model: def retimage(): from random

[web2py] Re: I am trying to change the background image every 5 seconds like this but this doesn't seem to work?

2016-06-13 Thread Anthony
You cannot call Python functions on the server from Javascript code running in the browser. The following line: {{getimage=retimage()}} will be called exactly once on the server *before *the HTML page is ever sent to the browser, and it will not result in anything being written into the