title: Ajax on Rails How to use Ajax append method for render HTML?
body: <p>I am not an English speaker.I ask of your understanding.sorry</p>
  
  <p><strong>/app/views/sale/index.html.erb</strong><br>
  I want to do ajax here </p>
  
  <pre><code>&lt;div class="col-lg-4" style="padding:5px;" id=reply_preview&gt;
  
        &lt;%= render 'sale/billpreview'%&gt;
  
  &lt;/div&gt; 
  </code></pre>
  
  <p>this is button for sending data</p>
  
  <pre><code>&lt;button type="submit" class="btn btn-defalut reply_sale" value="&lt;%= m.id %&gt;" name="menuid"
  </code></pre>
  
  <p>script</p>
  
  <pre><code>&lt;script&gt;
  $(".reply_sale").click(function(){
  
      send_value=this.value;
  
    $.ajax({
      method: "POST",
      url: "/sale/billpreview",
      data: { menuid : send_value },
      dataType : 'json'
    })
    .done(function() {
    $( "#reply_preview" ).append( "&lt;%= render 'sale/billpreview'%&gt;");// &lt;-- error point
    });
  
   });
  &lt;/script&gt;
  </code></pre>
  
  <p>here is error point</p>
  
  <pre><code>$( "#reply_preview" ).append( "&lt;%= render 'sale/billpreview'%&gt;");// &lt;-- error point
  </code></pre>
  
  <p>What do i type here?<br><br><br></p>
  
  <p><strong>/app/views/sale/_billpreview.erb</strong></p>
  
  <pre><code>&lt;div style="background-color:white; height:410px;"&gt;
    &lt;div style="padding:15px;"&gt;
      &lt;div style="color:black"&gt;
        &lt;h4&gt;order list&lt;/h4&gt;
        &lt;div&gt;=================================&lt;/div&gt;
        &lt;div style="height:250px; margin-left:1px; margin-right:1px;"&gt;
          &lt;div class="row" style="font-size:14px; height:200px;"&gt;
            &lt;% @total_price = 0 %&gt;
            &lt;% if current_user.store.billopen %&gt;
              &lt;% if @billshow.present? %&gt;
                &lt;% @billshow.salesmenu.each do |m|%&gt;
  
                  &lt;span class="col-lg-4"&gt;&lt;%= m.menu.name %&gt;&lt;/span&gt;
                  &lt;span class="col-lg-4"&gt;&lt;%= m.menu.price * m.qty %&gt;&lt;/span&gt;
                  &lt;span class="col-lg-4"&gt;
                    &lt;form action="/sale/qty_plus" method = "post"&gt;
                      &lt;button type="submit" class="glyphicon glyphicon-plus" name = "qty" value ="&lt;%=m.id%&gt;"&gt; &lt;/button&gt;
                    &lt;/form&gt;
                    &lt;span&gt;&lt;%= m.qty %&gt;&lt;/span&gt;
                    &lt;form action="/sale/qty_minus" method = "post"&gt;
                      &lt;button type="submit" class="glyphicon glyphicon-minus" name ="qty" value ="&lt;%=m.id%&gt;"&gt; &lt;/button&gt;
                    &lt;/form&gt;
                  &lt;/span&gt;
                  &lt;% @total_price = @total_price + (m.menu.price * m.qty) %&gt;
                &lt;% end %&gt;
              &lt;% else %&gt;
              &lt;% end %&gt;
            &lt;% else %&gt;
            &lt;% end %&gt;
  
          &lt;/div&gt;
          &lt;div&gt;--------------------------------------------------------&lt;/div&gt;
  
          &lt;div class="row"&gt;
            &lt;span class="col-lg-4"&gt;total price&lt;/span&gt;
            &lt;span class="col-lg-8" style="text-align:right"&gt;&lt;%= @total_price %&gt; &lt;/span&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div&gt;=================================&lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="row" style="margin-top:15px;"&gt;
  
        &lt;form class="col-lg-4" action="/sale/billfinish" method = "post"&gt;
          &lt;button type="submit" formmethod="post" formaction="/sale/billfinish" class="btn btn-default"&gt;완료&lt;/button&gt;
        &lt;/form&gt;
        &lt;form class="col-lg-4"&gt;
          &lt;button type="submit" onclick="location.href='/sale/index'" class="btn btn-default"&gt;Initialization&lt;/button&gt;
        &lt;/form&gt;
        &lt;form class="col-lg-4"&gt;
          &lt;button type="submit" onclick="location.href='/home/index'" class="btn btn-default"&gt;cancel&lt;/button&gt;
        &lt;/form&gt;
  
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt; 
  </code></pre>
  
  <p><strong>/app/controllers/home_controller.rb</strong><br></p>
  
  <pre><code>def billpreview
  
      if current_user.store.billopen
  
        @salesmenu = Salesmenu.new
        @salesmenu.menu_id = params[:menuid]
        @salesmenu.bill_id = current_user.store.bills.last.id
        @salesmenu.save
  
        @billshow = current_user.store.bills.last
  
      else #
        @bill = Bill.new
        @bill.store_id = current_user.store.id #db connect (bill &lt;-&gt; store)
        @bill.workperiod_id = current_user.store.workperiod.last.id #db connect (bill &lt;-&gt; workpeiod)
        @bill.save
  
  
        @salesmenu = Salesmenu.new
        @salesmenu.menu_id = params[:menuid]
        @salesmenu.bill_id = @bill.id
        @salesmenu.qty = 1 
  
        @salesmenu.save
  
        @billshow = @bill #current_user.store.bills.last
      end
  
      @temp_store = current_user.store 
      @temp_store.billopen = true
      @temp_store.save 
  
  return head :no_content
      #redirect_to :back
    end
  </code></pre>
  
  <p>also, i don't know what <code>return head :no_content</code> mean
  i just copy and paste at google.
  I'm not too sure if this is right.
  Am I correct? </p>