0
我用纯JavaScript(无jQuery和其他人不...)工作,我正在写一些代码,使一个AJAX请求。我注意到,当网络连接失败,在Chrome,Firefox和IE那些在xmlhttp.onreadystatechange:
检测Ajax请求无连接状态和状态
xmlhttp.readyState=4
xmlhttp.status=0
的值,因为我想处理网络连接问题,这是一个很好的办法做到这一点?
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==0){//No internet connection
//code to handle network error
}
}
此代码似乎为我工作,但我没有看到任何文件abuot这个,无处!你认为这是一个可靠的解决方案吗?