jQuery RJS inserting string vs dom.

Posted by Dmitriy Likhten on Stack Overflow See other posts from Stack Overflow or by Dmitriy Likhten
Published on 2010-04-13T19:58:38Z Indexed on 2010/04/13 20:22 UTC
Read the original article Hit count: 384

Filed under:
|

So I am trying to use jQuery to insert data from an ajax call.

I actually use the jquery.form plugin, and have the ajax form submitted with a dataType: 'script'.

The response is a jquery expression which contains a <%= javascript_escape(render ...) %> erb tag (similar to what the railscasts episode 136 instructs to do). However the end result is that the full text of the render is inserted as if that was the content to be inserted into the page, as text, not as dom elements.

Could the fact that the render had some newlines at the beginning be the cause?

Dom text: "\n \n &lt;li>....&lt;/li>"

I also tried having jQuery just read the response as a script and execute it, and used the prototype-based rjs stuff, same effect, the text is inserted into the dom. Are there any reasons why such a behavior would be experienced?

A bit of clarification:

My response.js.erb is

jQuery("#content").append("<%= escape_javascript(render(:partial => "widgets")) %>");
jQuery("#information").text("Finally, something happened!");

The full text inside the append() call is inserted as text into #content.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about jQuery