Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 717187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:23:05+00:00 2026-05-14T05:23:05+00:00

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

  • 0

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.

Update:

I’ve been doing some research into the problem. Turns out the reason why rails is escaping the <> characters is because it thinks it is rendering a regular .html file. The reason being that it has no indication that a .js is coming, because the post is done using an iframe (the post contains a file). If I add a .js to the end of the request I can do a respond_to do |format| format.js however it does not support http posts. Is there a way to configure it to accept posts on a .js request for an action?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:23:05+00:00Added an answer on May 14, 2026 at 5:23 am

    I’d guess it’s because you have dataType set to ‘script’. If you want the results of the AJAX call to be treated as DOM elements, change that to HTML.

    It also depends on how you’re inserting the results into the document. I doubt this is the case, but if you’re using .text() rather than .html(), you’ll get plain text rather than DOM elements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.