随着Firefox3的出现,想必很多人又多了不少烦恼:唉,又要多测试一种浏览器了。。

这里暂且记录下我遇到的第一个ajax有关FF3的“新特性”:在同步请求下,onreadystatechange事件是不起作用的,而在FF2,IE6,IE7下都是起作用的。

所以用同步请求的就需要注意了,一般需要用以下形式的代码:


var xhr = getXMLHttpRequest();

xhr.open(method, url, !sync);

xhr.send(para||null);


if(!sync)xhr.onreadystatechange = stateChange;

else stateChange();


function stateChange(){

if (4 == xhr.readyState){

if (200 == xhr.status){

//success

}else{

//failure

}

}

} ​​​