Javascript 为什么此文档.on(“第页:更改”)不执行?
我正在使用TurboLink,在我的视频/upload.js.erb中,我有以下内容:Javascript 为什么此文档.on(“第页:更改”)不执行?,javascript,jquery,ruby-on-rails,ruby-on-rails-4,turbolinks,Javascript,Jquery,Ruby On Rails,Ruby On Rails 4,Turbolinks,我正在使用TurboLink,在我的视频/upload.js.erb中,我有以下内容: $(document).on("page:change", "#video-submit", function() { console.log("Upload.js.erb has been executed"); }); 这是在此模式中执行的: <div id="overlay"> </div> <div class="popup" id="add
$(document).on("page:change", "#video-submit", function() {
console.log("Upload.js.erb has been executed");
});
这是在此模式中执行的:
<div id="overlay"> </div>
<div class="popup" id="add-video-step-1">
<div class="titles clearfix">
<h2>Upload a Video</h2>
<p><i>Step 1 of 2 - TESTING 1, 2, 3</i></p>
</div>
<div class="content">
<% if @family_tree %>
<%= simple_form_for([@family_tree, @video], :remote => true) do |f| %>
<div class="column">
<div class="f-row">
<%= f.input :title, label: "Title:" %>
</div>
## truncated for brevity
</div>
<%= f.button :submit, "Add Video", id: "video-submit" %>
<% end %>
<% end %>
</div> <!-- //content -->
</div> <!-- //popup -->
这是我的视频控制器:
然而,当我在模式中按下AddVideoSubmit按钮时,我没有看到任何输出到JS控制台的内容
这可能是什么原因造成的
编辑1
值得一提的是,我还尝试了document.onpage:load,但没有成功。我没有检查所有的TL选项-不确定它们是否相关。如果您使用来自控制器的js文件进行响应,为什么需要document.on?为什么不将文件更改为console.logUpload.js.erb已执行@ptd先生……你是一位英俊的学者,值得拥有世界上所有的财富。这是有道理的,而且奏效了。加上这个作为回答,我会接受的。
Started POST "/family_trees/1/videos" for 127.0.0.1 at 2014-12-02 10:19:16 -0500
Processing by VideosController#create as JS
Parameters: {"utf8"=>"✓", "video"=>{"title"=>"Blah", "description"=>"blah blah blah blah", "circa"=>"", "user_ids"=>[""]}, "commit"=>"Add Video", "family_tree_id"=>"1"}
User Load (2.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
## truncated for brevity
Redirected to http://localhost:3000/videos/59/upload
Completed 302 Found in 32ms (ActiveRecord: 15.5ms)
Started GET "/videos/59/upload" for 127.0.0.1 at 2014-12-02 10:19:16 -0500
Processing by VideosController#upload as JS
Parameters: {"video_id"=>"59"}
User Load (2.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
## truncated for brevity
Rendered videos/_upload_video.html.erb (3.3ms)
Rendered videos/_upload_video.html.erb (0.6ms)
Rendered videos/_upload_video.html.erb (0.9ms)
Rendered videos/_upload_video.html.erb (1.0ms)
Rendered videos/upload.js.erb (22.8ms)
Completed 200 OK in 298ms (Views: 31.7ms | ActiveRecord: 8.9ms)
def create
authorize! :read, @family_tree
@video = Video.new(video_params)
respond_to do |format|
if @video.save
format.html { redirect_to video_upload_path(@video) }
else
format.html { render action: 'new' }
format.json { render json: @video.errors, status: :unprocessable_entity }
end
end
end
def upload
authorize! :read, @family_tree
@video = Video.find(params[:video_id])
@upload_info = Video.token_form(@video, video_save_video_path(@family_tree, @video))
respond_to do |format|
format.html
format.js
end
end