直接这么写if(request.readState === 400 && request.status == 2)为什么发送错误了
var getDom = function(id){
if(id.substr(0,1) == '.'){
return document.getElementsByClassName(id.substr(1));
}else{
return document.getElementById(id);
}
};
getDom('search').onclick = function(){
var request = new XMLHttpRequest();
request.open('GET','server.php?number='+getDom('keyword').value);
request.send();
request.onreadystatechange = function(){ //过程进行监听,响应请求成功时,发生事件
if(request.readState === 400 && request.status == 2){
getDom('searchResult').innerHTML = request.responseText;
}else{
alert('发送错误')
}
}
}