Jquery does not run on the first page load!

0

Hello,

I have a page where the first loading of Jquery does not run, refreshing the page (refresh, F5) the function written in JQuery works.

I'm using JQuery with Ruby On Rails technology.

Solutions:

  • Add script at the end of HTML.
  • Removing Turbolinks from application.html.erb
  • Add function in application.js

NOTE: None of the above solutions worked.

Part of the JQuery function:

$(document).ready(function() {
    request_guides();
});


function request_guides() {
    //logica
}

It was also done this way

$(function() {
    request_guides();
});


function request_guides() {
    //logica
}

Anyone have ideas for a solution?

Thank you!

    
asked by anonymous 13.06.2017 / 14:32

2 answers

0

Try to do with pure javascript, see what happens:

document.addEventListener('DOMContentLoaded', function(){ 
    request_guides();
}, false);

If it does not work, let me know to remove the answer.

    
13.06.2017 / 14:39
1

Applied solution based on the response described in this topic, applying the appropriate changes for use with Ruby On Rails, without the need to add the scripts at the end of the body.

Tailored solution for JQuery:

$(document).on('turbolinks:load', function() {
    //Logica
});
    
13.06.2017 / 18:13