// 创建XMLHttpRequest对象 | |
var xhr=new XMLHttpRequest(); | |
// 请求行 | |
xhr.open('post','03-ajaxPost.php'); | |
//请求头 | |
xhr.setRequestHeader('Content-Type',' application/x-www-form-urlencoded'); | |
//请求主体 post send 设置数据 | |
xhr.send('name='+txt); | |
//监听服务器的响应 | |
xhr.onreadystatechange=function(){ | |
if(xhr.readyState==4&&xhr.status==200){ //这里表示接受服务器的响应成功的时候 | |
var r=xhr.responseText; | |
document.querySelector('.info').innerHTML=r; | |
} | |
} |