I don't think you are using jQuery.ajax correctly. The url should be the url 
to which the submitted form data should be sent. Also, the jQuery.ajax call 
does not appear to actually send any data (it takes a 'data' argument). See 
http://code.google.com/p/web2py/source/browse/applications/welcome/static/js/web2py_ajax.js#54
 for 
how web2py handles Ajax form submission.
 
Anthony

On Tuesday, August 23, 2011 11:04:01 AM UTC-4, mweissen wrote:

> Hi,
>
> I want do create a "dynamic form": 
> (1) On the top of a page there are several questions and 
> (2) at the end of the page a form should appear. 
>
> The content of the form depends on the answers of step (1).
> Therefore I tried to insert this new form using ajax.
> Result: the form appears, the submit-button works, but the content of 
> request.vars is always None.
>
> Here is the controller:
>
> def submittest():  
>     script = SCRIPT(""" 
>     function lf() {
>       jQuery.ajax({type: 'POST', url: 'ajax',
>     success: function(msg) {jQuery('#chk').html(msg); } })}; 
>     """)
>  
>     menu = MENU([['LoadForm',False,'javascript:lf()']])  
>     form = FORM(_name="myform")  
>     if form.accepts(request.vars, session):
>       result = request.vars.test
>     else:
>       result = 'No result'  
>
>    return dict(menu=menu, script=script, result=result, form=form)  
>
> def ajax(): 
>     checkboxes = [DIV(INPUT(_type='checkbox',_name='test', _value=v, ),v) 
> for v in ['a','b','c']]  
>     return str(FORM(INPUT(_type="submit"), *checkboxes,_name='myform'))
>
> And the view:
>
> {{extend 'layout.html'}}
> <h1>Submit</h1>
> {{=menu}}
> {{=script}}
> <div id='chk'>{{=form}}</div>
> Result: {{=result}}
>
> Maybe the problem is the line  form = FORM(_name="myform")
> Without this line form.accepts does not work. Two forms, one from the 
> controller, one created by ajax?
>
> Regards, Martin
>

Reply via email to