0

My sites navigation is within my <%= render 'layouts/header' %>. I want to use ajax so that when a user clicks on a navigation link, only the div id="content" refreshes. div id="content" is not a partial, is there a way to refresh the content of that div without using a partial?

<div id="container">
  <%= render 'layouts/header' %>
  <div id="content">
    <% flash.each do |key, value| %>
      <div class="flash <%= key %>"><%= value %></div>
    <% end %> 
    <%= yield %>
  </div>
</div>
thedeepfield
  • 6,138
  • 25
  • 72
  • 107

1 Answers1

0

You can do something like this

$.ajax({
        url: <url of handler>,
        dataType: "html",
        type: "POST",
        success: function (data) {
            if (data === undefined || data === null || data === "") {
                //display warning
            }
            else {
                $(<div selector>).html(data);                    
            }             
        }
    });

For more about jquery ajax refer http://api.jquery.com/jQuery.ajax/

Baz1nga
  • 15,485
  • 3
  • 35
  • 61
  • 1
    Actually, you'd want to extract the `
    ` from `data` beforehand. You can do that using something like this: `$('#content').replaceWith($(data).find('#content'))`.
    – Brian Donovan Dec 31 '10 at 16:49