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

  • SEARCH
  • Home
  • 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 6726897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:59:02+00:00 2026-05-26T09:59:02+00:00

I am doing an ajax call (using JQuery) and the Rails controller needs to

  • 0

I am doing an ajax call (using JQuery) and the Rails controller needs to return a partial so I can update the page after the ajax call. It seems to me there are 2 ways of doing this. In the controller, you filter for ajax calls (request.xhr?) and return:

  1. a .js.erb which gets executed on the client side as part of the Ajax call itself (dataType : script). This .js.erb file manipulates the DOM and injects the partials’ html, something like this:

    $(‘#content’).html(“<%= escape_JavaScript(render :partial => ‘success’) %>”);

  2. a partial ((dataType : html). You have a success callback method on the ajax call that then performs the inject, something like this:

    $.post( url, send_data,
    function( data ) {
    $( “#result” ).empty().append( data );
    }

These 2 solutions both work perfectly, I just don’t know which one is considered better coding practice and easier to maintain down the line.

  • 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-26T09:59:03+00:00Added an answer on May 26, 2026 at 9:59 am

    The second option is ideal. The Server should never be concerned with the Client.

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

Sidebar

Related Questions

I am doing an ajax call using jquery to get data in json format.
I am using jquery ajax method on my aspx page to call a web
I am using jQuery ajax call to return data as html to an empty
I'm doing an AJAX call using jQuery's JSON feature. function get_words_json(address, username, paging_value) {
Using jquery I am calling a php page using an ajax call. I call
I am doing Ajax call using jQuery and my URL is like http://localhost;3327/DummyAps/Demo.aspx In
I am doing an AJAX call that returns some HTML and jQuery: <div id='selected'>Here
i am doing an ajax call and i refresh a partial view. Inside the
I'm currently using jquery ajax to call a pagemethod (which works great); $.ajax({ type:
I have encountered a unique problem. I am doing a simple ajax call using

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.