I don't know why this function never return an readtstate == 4 for me.. <script type="text/javascript"> function trimite(url, parametri, divname){ if (window.XMLHttpRequest) { Ajax = new XMLHttpRequest(); } else if (window.ActiveXObject) { if(!Ajax){Ajax = new ActiveXObject("Msxml2.XMLHTTP");} if(!Ajax){Ajax = new ActiveXObject("Microsoft.XMLHTTP");} } function schimbari(){ if(Ajax.readyState == 4){alert('OK');} if(Ajax.readyState == 3){alert('Progrese');} alert('Status:'+Ajax.readyState); } Ajax.open('POST',url,true); Ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded') Ajax.onreadystatechange = schimbari(); } </script>
No , the problem is that i did Ajax.onreadystatechange = schimbari(); ... this is not valid it should be Ajax.onreadystatechange = schimbari otherwise it will loop just once, and i will never get an status 4 back ,only status 0 and 1 when i call it