bug & fix - invalid form traps if ajax redirect via web2py_ajax_page

146 views
Skip to first unread message

Carlos

unread,
Feb 15, 2011, 11:53:18 AM2/15/11
to web...@googlegroups.com
Hi,

I believe I found a bug and implemented a fix for the following ...

If we use web2py_ajax_page js function to load forms in the same page with ajax (as in my case, using jquery ui dialog), and if the xhr calls for a redirect, then web2py incorrectly traps the new forms (via web2py_trap_form js function) with the original url action, instead of using the new redirected url action.

I solved this by adding the following to the model (so it's applied to all web requests):

   response.headers['web2py-url'] = request.url

And by adding the following to web2py_ajax.html in web2py_ajax_page js function inside the 'complete' callback (as the first line):

   action = xhr.getResponseHeader('web2py-url') || action

A better solution, instead of using a custom 'web2py-url' header, could be to detect the current xhr url location (original action or new action if redirected) inside the 'complete' callback, but I don't know where to extract such value from the xhr object.

I believe this does not break anything, but I haven't tested it in detail.

Regards,

   Carlos

Carlos

unread,
Feb 15, 2011, 12:57:38 PM2/15/11
to web...@googlegroups.com
One change: use the following instead for the 'web2py-url' header setting:

   response.headers['web2py-url'] = request.env.path_info + '?' + request.env.query_string

My original post above (using request.url) was causing the query string to be lost after the redirection.

Regards,

   Carlos

Jonathan Lundell

unread,
Feb 15, 2011, 2:22:22 PM2/15/11
to web...@googlegroups.com

I haven't been following this thread, so I'm not sure what you're using the web2py-url header for. But if it's going to be submitted back to web2py, you're better off using URL() to generate it. I think.

Marc Smith

unread,
Feb 18, 2011, 1:56:49 PM2/18/11
to web2py-users
Doing what Carlos describes above also fixes my LOAD + component +
form issue described here:
http://groups.google.com/group/web2py/browse_thread/thread/378d78ab4a47ed6d/41de5a2254a07508


--Marc
Reply all
Reply to author
Forward
0 new messages