web2py - Controller function isn't called when using anchor tag callback

狂风中的少年 提交于 2019-12-11 05:33:48

问题


When a user visits a magazine page, a button should appear that will allow the currently logged in user to subscribe to a particular magazine if that user is already logged in. The button should not be visible to an anonymous user.

I have gotten the button to show up when the user has logged in, but clicking on the button doesn't call my controller function.

If this is the controller function:

@auth.requires_login()
def subscribe():
    mag_id = request.args(0, cast=int)
    db.subscribe.insert(magazine=mag_id, subscriber=auth.user.id)

And this is the part of the views:

<div>
    {{=magazine.title}}
    {{=magazine.description}}
</div>

<div>
{{ if auth.is_logged_in():}}
    {{=A('subscribe', _class="btn_subscribe", callback=URL("subscribe", args=magazine.id))}}
{{pass}}
</div>

The <a> button shows up as this:

<a href="#null" onclick="ajax('/myapp/default/subscribe/3',[],'me');return false">subscribe</a>

And the controller function is never called, and the user is never subscribed.


回答1:


As Anthony had suggested, adding the web2py.js was the solution.



来源:https://stackoverflow.com/questions/16307350/web2py-controller-function-isnt-called-when-using-anchor-tag-callback

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!