Javascript, function inside function problem -


hey, working javascript project , reached problem don't understand. here code, it's not 1 use in project, it's simplified version.

var x;  function fetchbox() {alert("worked");}  function a(m,n) {      x = new xmlhttprequest();      x.open("get", m, true);     x.onreadystatechange=function(){         n();          x.send();     }; }  a("http://jsfiddle/echo/xml/", fetchbox); 

i can change function make work:

function a(m,n) {      x = new xmlhttprequest();      x.open("get", m, true);     x.onreadystatechange=n();x.send(); } 

but in more complex version want add readystate function , few other things.

function a(m,n) {      x = new xmlhttprequest();      x.open("get", m, true);     x.onreadystatechange=         if(x.readystate===4){             n();              x.send();         }; } 

why can't include function inside function? jsfiddle link: http://jsfiddle.net/m6upv/17/

have weekend, ulrik

try way.

function a(m,n) {      x = new xmlhttprequest();      x.open("get", m, true);     x.onreadystatechange = function() {         if(x.readystate===4) {             n();              //x.send(); //look below         };     }     x.send() //i think, should here } 

Comments

Popular posts from this blog

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

apache - Add omitted ? to URLs -

php - How can I stop spam on my custom forum/blog? -