1

in my jquery post I have code like this

function checkBill(trs_id, bill_id){
    $.ajax({
      type: 'POST',
      url: "/check_bill",
      data: {bill_id: bill_id, transaction_id: trs_id},
      headers: {
        'X-CSRF-Token': '<%= form_authenticity_token.to_s %>'
      },
      dataType: 'script'
    });
  }

in my controller successfully get params for jquery post, but I get error missing template in my log? I don't know why? I guess jquery post not need template

Cœur
  • 37,241
  • 25
  • 195
  • 267
tardjo
  • 1,594
  • 5
  • 22
  • 38

2 Answers2

1

The missing template is basically a lack of check_bill.js.erb in your views folder


Views & Ajax

When your server receives a request (either HTTP or Ajax), it will process it by running the action & rendering the required view

Rails allows you to render HTML & JS views, which come in the form action_name.html.erb or action_name.js.erb. If you're sending a JS request, Rails therefore tries to render the .js.erb


Returning JS Requests

If you want to return JS requests, you'll need to use the code the other answers have stated (respond_to):

#app/controllers/your_controller.rb
def check_bill
    respond_to do |format|
        format.js { render :nothing => true } 
    end
end

The difference is what you want to return to Ajax. I'll update my answer if you let us know what kind of response you're expecting

Richard Peck
  • 76,116
  • 9
  • 93
  • 147
0

you should give instructions to your controller action to respond with a js. Like this:

 respond_to do |format|
   format.js {render :text => 'ok'}
 end

otherwise it will try to reply with an html view

sissy
  • 2,908
  • 2
  • 28
  • 54