Updated Answer
According to Mozilla docs , you are not using onreadystatechange with synchronous requests. Which makes sense since the request is not returned until the ready state is 4 (completed), although I probably would not have designed it that way.
Original answer
It is not immediately possible to see a smoking gun, but: Your ajax variable is not defined inside the function, and therefore you almost certainly rewrite it at each iteration of the loop in sprawdzstan . Does this remain a problem since you are using a synchronous ajax call. In any case, add var ajax; at checkstate to make sure you donβt fall prey to the horror of implicit globals .
Off topic . If you can find a way to reorganize your project so as not to use a synchronous ajax request, strongly recommend doing this. Synchronous requests block the browser user interface (more or less depending on the browser, but many of them are completely blocked, including other unrelated tabs). You can almost always reorganize and use an asynchronous request.
Beyond topic 2 : you are not using mouseEvent in your code, but if you were, you would like to get rid of these javascript: prefixes javascript: onmouseover and onmouseout . These attributes are not URLs, the prefix is ββnot (there) a protocol qualifier (this is a label that you are not using).
source share