The value new_likes from the controller is Ok?
Add
print new_likes
or
import pdb;pdb.set_trace()
before the return
Dne úterý, 20. května 2014 12:09:01 UTC+2 sasogeek napsal(a):
>
> I'm not sure if it's just me or it's the js file or it's the code I'm
> writing but something is definitely wrong... here's what's not working.
>
> Model (db.py)
> Answer=db.define_table(
> 'answers',
> Field('answer', 'text', requires=IS_NOT_EMPTY(), notnull=True,),
> Field('image', 'upload',
> requires=IS_EMPTY_OR(IS_IMAGE(extensions=('bmp', 'gif', 'jpeg', 'png',
> 'jpg')))),
> Field('question_id', db.questions, readable=False),
> Field('userid', db.auth_user, readable=False),
> Field('likes', 'integer', readable=False, writable=False, default=0),
> auth.signature
> )
>
> Controller (default.py)
> def like():
> answer = db(db.answers.id==request.vars.aid <http://request.vars.id>)
> new_likes = answer.select()[0].likes + 1
> answer.update_record(likes=new_likes)
> return new_likes
>
> View (index.html)
> <form><input type="hidden" id="answer_id" name="aid" value="{{=answer.id
> }}"/></form>
> <span id="answer{{=answer.id}}">{{=answer.likes}}</span> likes ·
> [<span onclick="ajax('like', ['aid'], 'answer{{=answer.id
> }}');">like</span>]
>
>
> When I click on like, it doesn't the value doesn't change! but I have the
> web2py.js script in my scripts... what is wrong?
>
> PS. I'm using web2py version 2.5.1
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.