Using ajax: How to respond to HTML requests made via AJAX in Rails on newest questions tagged ajax – Stack Overflow

I’m trying to write a Rails controller method that will respond to get requests made both “normally” (e.g. following a link) and via ajax.

Normal Case: The controller should respond with fully decorated HTML using the layout.

Ajax Case: The conroller should respond with the HTML snippet generated by the template (no layout)

Here’s the jQuery code, I’ve created to run on the client side to do the get request.

jQuery.get("http://mydomain.com/some_controller/some_action",
           {},
           function(data, textstatus) {
             jQuery("#target").html(data);
           },
           "html");

What’s the best way to handle this in Rails?

See Answers


source: http://stackoverflow.com/questions/1498694/how-to-respond-to-html-requests-made-via-ajax-in-rails
Using ajax: using-ajax



online applications demo