Why is my code not working? What correction has to be made?

50 views
Skip to first unread message

Steve Joe

unread,
Jun 10, 2016, 8:14:55 AM6/10/16
to web...@googlegroups.com
in .load file:
{{for i in range(0,3):}}
{{for j in range(0,3):}}
{{idd=str(i+1)+str(j+1)}}

<p id={{=idd}} style="display:inline" onclick=change({{=idd}})>
    {{=l[i][j]}}
</p>
{{pass}}
<br>
{{pass}}
<script>
    
    function change(id)
    {
        
        ajax('{{=URL('default','deciser')}}'+'?at='+id,[],id);
    }
    </script>



def deciser():
    return request.vars.at

def addgameplay():
    l=[]
    temp=[]
    for i in range(0,3):
        for j in range(0,3):
            temp.append('__')
        l.append(temp)
        temp=[]
    return locals()


in the function where .load has to run:
{{extend 'layout.html'}}
{{=LOAD('default', 'addgameplay.load', ajax=True)}}

def gameplay():
    
    return locals()



It does nothing! It doesn't update the id. I did some debugging and found that the id isn't passing correctly! How do I correct this?!

Anthony

unread,
Jun 10, 2016, 10:05:39 AM6/10/16
to web2py-users
In the browser network tab, what's happening with the Ajax requests? Are they being sent as expected, and if so, what response is returned?

Steve Joe

unread,
Jun 11, 2016, 11:41:40 AM6/11/16
to web2py-users
It does nothing.
However in 

 function change(id)
    {
        
        ajax('{{=URL('default','deciser')}}'+'?at='+id,[],id);
    }

when I change the second id to something '12' as in
 function change(id)
    {
        
        ajax('{{=URL('default','deciser')}}'+'?at='+id,[],'12');
    }
it works as expected. But when it id it doesn't show any response. Something's wrong there and I am unable to fix it.

Anthony

unread,
Jun 11, 2016, 9:02:20 PM6/11/16
to web2py-users
You're probably getting an error in the JS console. The ajax() function expects id to be a string, so try:

ajax('{{=URL('default','deciser')}}' + '?at=' + id, [], id.toString())

Anthony

Anthony

unread,
Jun 11, 2016, 9:12:10 PM6/11/16
to web2py-users
Actually, I'm not sure whether the "#" + id query selector will work if id is a number (even if converted to a string), so you might be better off pre-pending the id with a letter.

Anthony

Steve Joe

unread,
Jun 12, 2016, 11:51:36 AM6/12/16
to web2py-users
Thank you Anthony, it worked!
Reply all
Reply to author
Forward
0 new messages