Bak
Bak

Reputation: 365

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

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.

Upvotes: 1

Views: 993

Answers (1)

Bak
Bak

Reputation: 365

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

Upvotes: 1

Related Questions