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
Post a Comment