I tried that... no luck. I think it's because there's multiple answers and
all of them have the form input with name="aid", can't distinguish which
request.vars.aid to send... different answers would have different amounts
of likes... there's a for-loop statement above the form and each form has
the same name... if i distinguish the name to be name="aid{{=answer.id}}",
how do I get the value in the controller? request.vars.aid?
On Tuesday, 20 May 2014 13:40:44 UTC, Anthony wrote:
>
> ajax('like', ...)
>
> In the above, 'like' is a relative URL (i.e., it doesn't start with a
> "/"), which means it will simply be appended to the URL of the current
> page. Instead, use the web2py URL helper:
>
> ajax('{{=URL('default', 'like')}}', ...)
>
> Anthony
>
>
> On Tuesday, May 20, 2014 6:09:01 AM UTC-4, sasogeek wrote:
>>
>> 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.