jQuery RJS inserting string vs dom.
- by Dmitriy Likhten
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 <li>....</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.