web2py AJAX is not working if the proper URL has not been used

At the moment, I’m playing around with web2py (a nice full-stack bundle to develop Python Web Applications).

I created a simple AJAX button which just shows a simple message:

AudacityControlWeb/views/default/index.html:

[...]
<form>
    <input id="set_mark_newparagraph" type="button" value="{{=T('mark: new paragraph')}}" onclick="ajax('set_mark_newparagraph_onclick','leer','output')" class="btn-large btn-huge">
</form>
[...]

AudacityControlWeb/controllers/default.py:

[...]
def set_mark_newparagraph_onclick():
    response.flash=T('marked a new paragraph')
    return T('marked a new paragraph')
[...]

I called http://127.0.0.1:8000/AudacityControlWeb/default/index and clicked the button. Everything is working perfect.
As I’m developing this tool for an Android device, I also called it on my Android Chrome. Of course I’m lazy and just called http://127.0.0.1:8000/AudacityControlWeb instead of the whole URL. The page shows up, as the default controller with the index action is invoked automatically.
But it didn’t work. The button just did not do anything. I connected my Android via USB Debugging and found out it tried to call http://127.0.0.1:8000/set_mark_newparagraph (which, of course, does not work).
So remember, always call the full URL http://127.0.0.1:8000/AudacityControlWeb/default/index instead of being lazy.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert