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 7408689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:57:31+00:00 2026-05-29T05:57:31+00:00

I am doing Ajax Call from View, then controller is fetching data from DB

  • 0

I am doing Ajax Call from View, then controller is fetching data from DB into an Array, now this array value I want to pass to JavaScript, so that I can update data in a table with different id’s

Controller code:

def AjaxView
 @var1 = Var.find(:all,:conditions => { :varname=> "one" },:select=> (params[:col]))
  respond_to do |format|
   format.js 
  end
end

AjaxView.js.erb code:

$(document).ready(function() {
   $("#test").text("valuetoupdate");
  });

Now when I run this code it successfully update “valuetoupdate” at id =test in view page.
Instead of this I want to update all values one by one from array @var1.

I searched more and realized that array @var1 generated in Controller will automatically get transferred to AjaxView.js.erb file. Now I have to iterate over all values, but this code doesn’t work in JavaScript file:

<% for var in @var1 %>
$("#3").text(var);
<% end %> 

it gives blank response

  • 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-29T05:57:32+00:00Added an answer on May 29, 2026 at 5:57 am

    Thanks Guys,

    I am able to resolve my issue, in following manner,
    I moved away from for loop implementation, instead start using if else condition,

       <% if @var.to_s == 'valuetoupdate' %>
        { }
       <% elsif @var.to_s == 'valuetoupdate1' %>
        {}
    

    And it worked fine for me.

    • 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 and i refresh a partial view. Inside the
I would like to keep model binding when doing ajax calls from my view.
I am trying to make a function return data from an ajax call that
Is there any way to debug a call coming from an AJAX post? This
I have a div that is receiving content from an ajax call. Right now
I am doing an Ajax call from site.com/users/{username} i wanna access the url site.com/account/deleteComment
I am doing an AJAX call to a controller method on my ASP.Net MVC
After doing so: $.ajax({ type: POST, url: $(#form).attr(action), data: value= + value + &sel=
I am having problems passing my model from my view via an Ajax call
I am doing an AJAX call that returns some HTML and jQuery: <div id='selected'>Here

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.