Note that there are some explanatory texts on larger screens.

plurals
  1. POdocument.ready function being called over and over
    text
    copied!<p>I have an html site that doesn't have page changes. It just loads different elements into each position on the page using ajax calls. I need my login function to run after the page is loaded the first time (because it requires elements on index to exist), but when I use $(document).ready(login), it fires every time an element is loaded (since it loads elements onto the page, it gets stuck in an infinite loop). Other than placing it at the bottom of my index page (which seems pretty fragile) is there a way to make it load after the index page is finished loading, but not have it run everytime an ajax request adds something to the page? </p> <p>My login function looks like this:</p> <pre><code>function login () { if($.cookie('employee')) employee = $.cookie('employee'); if(employee &amp;&amp; !employee.login) $("div.middle").load('login.html'); else $("div.middle").load('main.html'); } function logout () { //FIXME send a logout request to server to end session also employee = null; $.cookie('employee', null); $("div.middle").load('login.html'); } </code></pre> <p>and my initial ready function looks like: //Global variables var employee = new Object;</p> <pre><code>$(document).ready(function(){ $("div.leftColumn").html(buildLeftNav()); //set height of middle if height of leftColumn is less than height of middle if($("div.leftColumn").css('height') &lt; $("div.middle").css('height')) $("div.center").css('height' , $('div.middle').css('height')); //handle login and logout $.cookie.json = true; login(); }); </code></pre> <p>I have set up a fiddle to illustrate: <a href="http://jsfiddle.net/uZVP4/" rel="nofollow">http://jsfiddle.net/uZVP4/</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload