var xhr ;
if( window.XMLHttpRequest ) { // IE7+ 、Firefox 、Chrome 、Opera支持
xhr = new XMLHttpRequest();
}
else {
xhr = new ActiveXObject( "Microsoft.XMLHTTP" ); // IE5、IE6
}
xhr.timeout = 3000 ;
xhr.open( "GET", url , true ) ;
xhr.onload = function() {
if( ( xhr.status >= 200 && xhr.status < 300) || xhr.status == 304 ) {
var responseText = JSON.parse(xhr.responseText) ;
console.log( responseText ) ;
}
else {
console.log( '服务器异常' ) ;
}
}
xhr.timeout = function() {
console.log( '请求超时' ) ;
}
xhr.send() ;