[Solved] ruby on rails 4/jquery/javascript: button only works after page reload


Line 433 of http://new.mapmill.org:3000/assets/sites.js

$('#upload_more').click(function() {
  return window.location.href="https://stackoverflow.com/sites/" + $('#site_id').val() + "/upload";
});

You are binding the event handler on DOM ready, but your page content is loaded dynamically. So at the time you binding the event, $('#upload_more') doesn’t even exist in the DOM.

In my experences this is commonly happened when someone is developing a single page app (aka SPA) for the first time. Check the bound events in devtool (Event Listeners tab in Elements), and you will find something is wrong.

enter image description here

4

solved ruby on rails 4/jquery/javascript: button only works after page reload