My Problem
xmlhttp.readyState
is always 2
then 3
in firefox and other browsers in Internet Explorer the opposite, and 1
and 4
is missing.
My Code
function like(id,type){
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
var element = document.getElementById('answersLoader'+id);
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var result = xmlhttp.responseText; // the result from AJAX response
} else {
// FOR stackoverflow users: I've checked here the state and status with this:
// alert(' state: ' + xmlhttp.readyState +' status: '+xmlhttp.status);
// The status result is always 200 but the state firstly is 2 then 3 in firefox and other browsers, in IE the opposite.
element.innerHTML="<img src=\"http://localhost/images/default/icons/loader.gif\" />";
}
}
xmlhttp.open("GET", "http://localhost/ajax/like.php?id="+id+"&type="+type, true);
xmlhttp.send();
}