I’m having troubles with rendering response via AJAX.
Here is how my .js.haml view looks like:
:plain
$("#cart").replaceWith("#{escape_javascript(render 'carts/cart')}");
HTML code in partial is rendered incorrectly and breaks HTML layout. In web inspector of Safari, I’m getting following XHR response:
$(“#cart”).replaceWith(” Your orderh2>
I is clear, that HTML code is broken: h2 tag is not closed properly, attribute values are not enclosed in brackets etc.
A part of page, that was replaced with such a response will be broken.
I’ve also tried some other techniques, like this:
!= "$('#cart').replaceWith('#{escape_javascript(render 'carts/cart')}');"
The result is the same.
However, simple cases, like
:plain
$("#cart").replaceWith("<p>Test</p>");
Are working fine.
The problem is in rendering of the partial.
PS: This partial is 100% correct, because it is used by regular page rendering.
What can be wrong here.
Thanks.
I’ve found the reason. escape_javascript function work incorrectly, because of a bug, found in Rails 3.0.8.