简体   繁体   English

在Rails中进行Ajax调用后,部分不被更新

[英]Partial is not being updated after ajax call in Rails

in my action.js.erb file 在我的action.js.erb文件中

$("#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 在我的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. 我正在对动作进行ajax调用,然后在action.js.erb文件中,我通过呈现相同的局部值(但具有更新的值)来更新div的html,但是partial不呈现更新的值。 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(). 尝试在调用.html()之前和之后添加警报消息。 Do both alerts pop up? 两个警报都弹出吗? If so, that means the issue most likely isn't with your javascript. 如果是这样,则意味着问题很可能与您的JavaScript无关。

Yes this is a problem request must be of type "js", please provide how you are making ajax call? 是的,这是一个问题请求,必须为“ js”类型,请提供您如何进行ajax调用? that is the view part of it 那是其中的一部分

Why do you replace the existing values of <div id="performance"> </div> . 为什么要替换<div id="performance"> </div>的现有值。 Try to append the new values by using append method in js. 尝试通过使用js中的append方法来附加新值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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