I made some javascript code for my website, it works without problem on opera and chrome, but not on firefox.
Here is script:
function checkstate(who,row,cell) {
var zwrot="";
var mouseEvent='onmouseover="javascript:bubelon(this.id);" onmouseout="bubeloff();"';
var cellid="";
ajax=new XMLHttpRequest();
ajax.onreadystatechange=function(aEvt) {
if (ajax.readyState===4 && ajax.status===200) {
alert("im here!");
}
};
ajax.open('GET',"oth/work_prac_stan.php?usr="+who,false);
ajax.send();
}
function sprawdzstan() {
var lol="";
var table = document.getElementById("usery");
var re = /^<a\shref\=/g;
for (var i = 1, row; row = table.rows[i]; i ++) {
if (row.cells[0].innerHTML.match(re)) {
checkstate(row.cells[1].innerHTML,row,2);
} else {
checkstate(row.cells[0].innerHTML,row,1);
}
}
}
The problem is, that firefox is not running function assigned to onreadystatechange. I checked in firebug, that response from php file is correct.
Where is the problem? It works on chrome and opera, firefox just dont, no error in console, nothing.
Updated answer
According to Mozilla’s docs, you don’t use
onreadystatechangewith synchronous requests. Which kind of makes sense, since the request doesn’t return until the ready state is 4 (completed), though I probably wouldn’t have designed it that way.Original answer
Not immediately seeing a smoking gun, but: Your
ajaxvariable is not defined within the function, and so you’re almost certainly overwriting it on every iteration of the loop insprawdzstan. Whether that’s a problem remains to be seen, since you’re using a synchronous ajax call. In any case, add avar ajax;tocheckstateto ensure that you’re not falling prey to the Horror of Implicit Globals.Off-topic: If you can possibly find a way to refactor your design to not use a synchronous ajax request, strongly recommend doing that. Synchronous requests lock up the UI of the browser (to a greater or lesser degree depending on the browser, but many — most? — completely lock up, including other unrelated tabs). It’s almost always possible to refactor and use an asynchronous request instead.
Off-topic 2: You aren’t using
mouseEventin your code, but if you were, you would want to get rid of thosejavascript:prefixes on theonmouseoverandonmouseoutattributes. Those attributes are not URLs, the prefix is not (there) a protocol specifier (it’s a label, which you’re not using).