javascript - AJAX loop, calling function onload vs. manually in the console/code -


i have 2 functions:

function find_existing_widgets(){     xmlhttp = new xmlhttprequest();     xmlhttp.open('get', './_includes/check-load-user-settings.php', true);     xmlhttp.onreadystatechange = open_existing_widgets;     xmlhttp.send(null); }   function open_existing_widgets(){     if(xmlhttp.readystate==4 && xmlhttp.status==200)     {         xmlresponse = xmlhttp.responsexml;         root = xmlresponse.documentelement;          var widget_id = root.getelementsbytagname('widget_id');         var name = root.getelementsbytagname('name');         var type = root.getelementsbytagname('type');         var value = root.getelementsbytagname('value');          for(i= 0; i< name.length; i++)         {             nametext = name.item(i).childnodes[0].nodevalue;             widgetid = widget_id.item(i).childnodes[0].nodevalue;             //var value = name.item(i).firstchild.data;             alert(nametext);             nametext = nametext.replace(/\s+/g,'_');             //alert(value); works             widget_creator();             load = "./widgets/"+nametext+"/index.php?widget_id="+widgetid;             //alert(load);  works             $('.wrapper:first .main_sec').load(load);             $('.wrapper:first').fadein(1000);         }      } }` 

4 scenarios:

one. running function find_existing_widgets() onload on <body> tag , works perfect. runs once , shows data accordingly

two. running same function before </body> tag like: <script>find_existing_widgets()</scripts> , causes infinite loop.

three. running same function window.onload = find_existing_widgets(); in js code. , cause same issue two, infinite loop.

four. if run manually console works perfectly.

why loop? what's difference ?

once there you'll see execution looping. using ajax, javascript can seen in dev tools in chrome.

example:

josesebastianmanunta.com/animated3/login.php user: smanunta pass: password


Popular posts from this blog