function ajx(url) {
var xhri = xhrRequest('xml');
var ajxOut = '';
var out = '';
xhr[xhri].open('GET', url, true);
xhr[xhri].setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset='+document.characterSet);
xhr[xhri].onreadystatechange = function() {
console.log(xhr[xhri].readyState);
if (xhr[xhri].readyState == 4 && (xhr[xhri].status == 200 || xhr[xhri].status == 205)) {
doSomething();
}
}
使用此函数的ajax调用会导致chrome和firefox的结果不同:在firefox中,会调用doSomething,因为onreadystatechange会被多次调用并最终传递readyState == 4。但是,在chrome中,onreadystatechange被调用一次并记录readyState == 0。怎么会这样?