admin管理员组文章数量:1356965
I have a custom js
file in app/assets/javascripts
.
This is the js file:
//app/assets/javascripts/contacts.js
//$(document).ready(function() { //I've already tried with this method
$(window).load(function() {
alert("foo bar")
});
I require the file contacts.js
file in the application.js
file.
If I inspect the html page I see the js file loaded correctly, but the message is not shown. If I reload the page (by pressing f5), the message is correctly show.
When the page is loaded the javascript is loaded (I can see it in source html code in the browser) but not executed.
Can you help me?
SOLUTION: Rails 4: how to use $(document).ready() with turbo-links
I have a custom js
file in app/assets/javascripts
.
This is the js file:
//app/assets/javascripts/contacts.js
//$(document).ready(function() { //I've already tried with this method
$(window).load(function() {
alert("foo bar")
});
I require the file contacts.js
file in the application.js
file.
If I inspect the html page I see the js file loaded correctly, but the message is not shown. If I reload the page (by pressing f5), the message is correctly show.
When the page is loaded the javascript is loaded (I can see it in source html code in the browser) but not executed.
Can you help me?
SOLUTION: Rails 4: how to use $(document).ready() with turbo-links
Share Improve this question edited May 23, 2017 at 11:53 CommunityBot 11 silver badge asked Apr 2, 2014 at 12:34 user1066183user1066183 2,5844 gold badges29 silver badges57 bronze badges 5-
Yes, I'm using
turbo-links
– user1066183 Commented Apr 2, 2014 at 12:43 - 2 read this – Roman Kiselenko Commented Apr 2, 2014 at 12:44
- 1 possible duplicate of Rails 4: how to use $(document).ready() with turbo-links – Roman Kiselenko Commented Apr 2, 2014 at 12:45
- Ok. Your link works for me. solved. – user1066183 Commented Apr 2, 2014 at 12:52
-
In rails 5, you can simply say
$(document).on('turbolinks:load', function() { ... });
– Mark Commented Oct 25, 2016 at 4:28
2 Answers
Reset to default 7$(document).ready(function() { } # Not working with turbo-links
From
Turbolinks overrides the normal page loading process, the event that this relies on will not be fired. If you have code that looks like this, you must change your code to do this instead:
$(document).on('ready page:load', function () {
// you code here
});
Another question
With Turbolinks version 5 (starting from Rails 5) you need to use:
$(document).on("turbolinks:load", function () {
// YOUR CODE
});
本文标签: Ruby on Rails 4 javascript not executedStack Overflow
版权声明:本文标题:Ruby on Rails 4 javascript not executed - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744033652a2579372.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论