ravenspoint
ravenspoint

Reputation: 20472

web2py ajax call fails from pages other than index

I am using the web2py ajax function, like this:

In index.html

{{=INPUT(_name='total_buy', _onkeyup=
  "ajax('key',['total_buy'], ':eval')")}}

<div id="target"></div>

and in default.py

def key():
return "jQuery('#target').html('%s');" % repr(float(request.vars.total_buy))

This works perfectly. When a number is typed into the input field, it is immediatly echoed to the target div.

However, when I copy this to another page it stops working. I do not see the input number being echoed.

For example, I move the code from index.html to plan.html and leave everything else untouched, I continue to see the echo in the index page, but not in the new plan page.

Taking a look at the server log, I see this:

127.0.0.1, 2011-10-15 13:55:50, POST, /medaim/default/key, HTTP/1.1, 200, 0.047000
127.0.0.1, 2011-10-15 13:55:52, POST, /medaim/default/key, HTTP/1.1, 200, 0.047000
127.0.0.1, 2011-10-15 13:55:52, POST, /medaim/default/key, HTTP/1.1, 200, 0.078000
127.0.0.1, 2011-10-15 13:55:59, GET, /medaim/default/plan/1, HTTP/1.1, 200, 0.094000
127.0.0.1, 2011-10-15 13:56:01, POST, /medaim/default/plan/key, HTTP/1.1, 500, 0.250000
127.0.0.1, 2011-10-15 13:56:01, POST, /medaim/default/plan/key, HTTP/1.1, 500, 0.218000
127.0.0.1, 2011-10-15 13:56:02, POST, /medaim/default/plan/key, HTTP/1.1, 500, 0.265000

It seems like, from the plan page, it is calling /medaim/default/plan/key rather than /medaim/default/key

How do I deal with this?

Upvotes: 1

Views: 611

Answers (1)

Anthony
Anthony

Reputation: 25536

Try

{{=INPUT(_name='total_buy', _onkeyup=
    "ajax('%s', ['total_buy'], ':eval')" % URL('default', 'key'))}}

Upvotes: 1

Related Questions