简体   繁体   中英

Partial is not being updated after ajax call in Rails

in my action.js.erb file

$("#performance").html("<%= escape_javascript(render 'performance_table',questions: @questions, groups: @groups, performances: @performances) %>")

in my view

<div class="col-xs-5">
  <div id="performance">
   <%= render 'performance_table', :questions => @questions, :groups => @groups, :performances => @performances  %> 
  </div>
 </div>

in my controller_action

@groups = classroom.groups
@questions = @quiz.questions
@performances = Array.new
i = 0
group_ids.each do |g|
  question_ids.each do |q|
    @performances.push(Answer.where("group_id = ? AND question_id = ?",g,q).first.userans)
  end
end

I am making an ajax call to an action and then I in the file of action.js.erb I am updating the html of my div by rendering the same partial but with updated values but partial is not rendering updated values. Kindly let me know what I am doing wrong . console is also showing no error at all

Try adding an alert message before and after you call .html(). Do both alerts pop up? If so, that means the issue most likely isn't with your javascript.

Yes this is a problem request must be of type "js", please provide how you are making ajax call? that is the view part of it

Why do you replace the existing values of <div id="performance"> </div> . Try to append the new values by using append method in js.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM