我想更新我的rails應用程序中的div。 Iam剛剛學習ROR。所以它是我的學習舞臺,請找到代碼。 鑑於網頁...Ruby on Rails + Ajax
<%= javascript_tag do %>
jQuery(function($)
{
$("#tabs4").click(function()
{
$.ajax(
{
url:'/spaces/showcal',
type:'GET'
});
});
});
<% end %>
在空間控制器..
def showcal
respond_to do |format|
format.html
{
render (:update) { |page|
page.replace_html 'tab4', :partial => 'spaces/showcal'
}}
end
end
我在做什麼錯在這裏。請幫忙 我也有一個泛音頁面(_showcal),其中有一些文本顯示到該div。
反正。你能告訴我爲什麼我們應該使用respond_to do | format | format.html format.js – rubyist
format.html和format.js是一種響應不同響應類型的方法。也許你想渲染或返回一些有所不同,取決於預期的格式。如果你沒有respond_to塊,你的控制器動作就會變成你正在進行的渲染方法調用,因爲它每次只會執行一步。 – agmcleod