page.replace_html for entire div not partial?
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>
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/
精彩评论