Javascript doesn't do nothing before the end of the entire script! If I try to execute the function prova() from the following simple code, it prints only the variable "risultato" without showing people the image attendi.gif! In other browser, like Mozilla, it shows the image during the XmlHttpObject ... waiting, and when it receives the result it substitutes the image with the result! function GetXmlHttpObject() { var objXMLHttp=null; if (window.XMLHttpRequest) { objXMLHttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP"); } return objXMLHttp; } function prova() { var newdiv = document.createElement("div"); newdiv.setAttribute('id', 'extra'); var vecchio = document.getElementById('extra'); vecchio.parentNode.replaceChild(newdiv,vecchio); var newimg = document.createElement("img"); var src='images/attendi.gif?'+variab;newimg.setAttribute('src', src); newimg.setAttribute('alt', 'Attendi ...'); document.getElementById('extra').appendChild(newimg); } var xmlHttp = GetXmlHttpObject(); var i=0; var url="http://www.mysite.com/script.php"; if (!xmlHttp) { alert ("Browser does not support HTTP Request"); return; } xmlHttp.open("GET", url, false); xmlHttp.send(null); var risposta=xmlHttp.responseText; risposta = risposta.replace("<","<"); risposta = risposta.replace(">",">"); if (risposta=='bye') { risultato="YES"; } else { risultato="NO"; } var newdiv = document.createElement("div"); newdiv.setAttribute('id', 'extra'); var vecchio = document.getElementById('extra'); vecchio.parentNode.replaceChild(newdiv,vecchio); var newgrassetto = document.createElement("b"); newgrassetto.setAttribute("style","color:red;"); newgrassetto.innerHTML=risultato; document.getElementById("extra").appendChild(newgrassetto); }
Please don't use synchronous XMLHttpRequest. The Mozilla behavior where it only partially freezes the browser causes a lot of other bugs, so we do not intend to do the same.
For Apple employees: this is <rdar://problem/6653209>.
*** Bug 84032 has been marked as a duplicate of this bug. ***