On 02/01/2010 07:15 PM, Vladimir Dronnikov wrote:
> My templates behave differently depending on which way they were
> requested. If requested in "vanilla" way, they should serve complete
> HTML markup. If requested via AJAX\c\c\c\c:) _x_requested_with, they
> should serve just bare contents. That is evident part.
>
> Now quirky one. I load a bare form into jquery-ui dialog() and setup
> the form be ajaxSubmit()ted. User submits the form and if the request
> was OK, controller serves an empty string and I close the dialog. If
> request is not OK, controller serves the content (with errors) of
> validating form, I see the answer is not an empty string and reload
> that content back to the dialog for further editing. This method
> degrades gracefully for javascript-less clients to just plain pages
> (of complete HTML markup). So to know how the form was submitted is
> critical here. This can be easily done analysing request.is_xhr
> property.
>
> This technique has been working well until the forms start to contain
> upload fields. I pull the initial content of the form into the dialog
> well, but upon receiving the request, the controller goes to wrong
> branch (since request.is_xhr is False) and serves complete markup
> instead of empty string.
>
> I'm pretty sure people exist facing the same problem. Thus the post.
>
> --
> Vladimir
>
>   

I understand your problem. I don't know how and if you can modify jQuery
(I use it only for the effects), but I solve that problem by sending
proper Accept header. If it is application/json, the controller returns
json data. If it contains text/html (which will also be the case for
"plain" requests with no JS), it returns templated HTML. I also solve
errors with http status codes, and the JS (xhr) client that received the
response will only show the content if it is text/plain, in order to
avoid inserting entire formatted HTML page into the <div> that shows
action results.


Vlad

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to