0
使用Rails 3.2。這是一個簡單的Ajax加載,我編碼:在Rails中顯示ajax加載器圖像
# places/revisions.html.erb
<a href="<%= version_path(version) %>" class="diff">View changes</a>
<div id="version"><!-- #version used for ajax -->
Click "View changes" to see the diff.
</div>
<% content_for :javascript_onload do %>
$('a.diff').attr('data-remote', 'true');
<% end %>
# versions_controller.rb
class VersionsController < ApplicationController
def show
@version = Version.find(params[:id])
end
end
# versions/show.js.erb
$('#version').html('<%= escape_javascript render :partial => "versions/version", :locals => {:version => @version} %>');
的<div id="version"></div>
是要去與通過Ajax的新內容獲取所取代。雖然它仍然在加載,但我想在的View changes
旁邊添加圖像加載器。我應該怎麼做?
我不確定url:或data:應該在我的代碼中。我怎麼能找到這個? – anmaree
網址是你的網址你想發送ajax請求,在這個例子中,它是鏈接的原始href。數據是你的url參數,如果你的url包含完整的參數,那麼你不需要它。請閱讀api:http://api.jquery.com/jQuery.ajax/ – Bigxiang