Hey, I was working with a javascript project and reached a problem that I just don't understand. Here is the code, it's not the one that I use in my project, but it's a 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 easily change the function to make it work:
function A(m,n) {
x = new XMLHttpRequest();
x.open("GET", m, true);
x.onreadystatechange=n();x.send();
}
But in my more complex version I want to add a readyState function and a 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 I include a function inside this function? JsFiddle link: http://jsfiddle.net/M6Upv/17/
Have a good weekend, Ulrik