跪求各位js高手,为什么ajax没有得到ajax.php文件???

2025-03-22 02:13:22
推荐回答(1个)
回答1:

xhr.responseText  不能直接  alert ,得在 xhr 对象的回调函数里才能获取到

xhr.onreadystatechange = function(){
    //Ajax状态码等于4:接收数据完成(服务器端处理完所有数据并返回数据)
    if(xhr.readyState==4){
         alert(xhr.responseText);
    }
}