Which controller is displaying the view you have posted? It looks like the 
ajax function is calling the same controller which returns the index page.

The controller function called by the ajax function should return a string.
The string can be jquery which will be evaluated if you use ':eval'. Or it 
could be some text, like: 'The answer: xxx' which you can dump into a div 
without refreshing the page.

*VIEW for default/index:*
{{extend 'layout.html'}}

<div id="answer_location">The answer: {{=answer}}</div>

<form id="myform">
<input name="name"/> <input type="submit" />
</form>

<script>
$('document').ready(function(){
$('#myform').submit(function() {
ajax("{{=URL('default', 'new_answer')}}",['name'], 'answer_location');
return false;
});
});
</script>

*CONTROLLER:*
def index():
    answer=0
    return locals()

def new_answer():
    form = SQLFORM(db.post)
    if form.accepts(request, formname=None):
        info = request.vars.get('name', 0)
        if info:
            try:
                return 'The answer: {0}'.format(int(info)-200)
            except ValueError:
                return 'Bugger... should have better form validation.'
    elif form.errors:
        return TABLE(*[TR(k, v) for k, v in form.errors.items()])

 

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to