3
我要求动作Home#index
对HomeController
中的空操作进行调用。从呈现html.erb和js.erb中停止Rails 3.2
页面在HTML中加载得很好,这正是我所期望的(呈现home/index.html.erb
,但是它也加载了相应的js,并且在到达100ms之后(渲染home/index.js.erb
),我怎样才能阻止它?只需要的JavaScript回应时,我要求它,而不是通过一个HTTP GET请求。
的HomeController
class HomeController < ApplicationController
respond_to :html, :js # Nothing changes whether I have this or not
def index
respond_to do |format| # Nothing changes whether I have this or not
format.html
format.js
end
end
end
的routes.rb
Ajaxtest::Application.routes.draw do
get "home/index"
root to: 'home#index'
end
index.html.erb
<p>Find me in app/views/home/index.html.erb.</p>
index.js.erb的
$("#content").html("Lorem ipsum dolor sit amet, yo non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
document.title = "AJAX loaded";
这样做会导致它无法通过HTTP GET请求对HTML做出响应。还是)感谢你的建议! – joseph 2012-02-15 03:45:53