Hassan Munir Hassan Munir - 2 months ago 7
Ajax Question

Want to add dynamic list with dynamic data through js

There is a main file in which i want to add li in ul with dynamic value.

<ul class="selected_questions"></ul>

In my js.erb i want to show title. I have debugged it and @ques value is there but not showing in ul. Following is my code.

<% if @ques.errors.any? %>

$('#dialog-form').html('<%= escape_javascript(render('form')) %>');
<% else %>
$(".selected_questions").append('<li><span class="tab">"'+@ques.title+'"</span></li>');
<% end %>

I also have tried following way :

$('<li />', {html: @ques.title}).appendTo('ul.selected_questions')

Simple string is appended successfully but object from controller not been shown. What am i doing wrong ???


Try this

change this

 $("#selected_questions").append('<li><span class="tab">"'+@ques.title+'"</span></li>');


$("#selected_questions").append('<li><span class="tab"><%= @ques.title %></span></li>');