post请求数据
注意事项:
(1)不需要encodeURI()转码;
(2)发送的数据 写入在send()中;
(3)添加 post请求的数据的 头 数据格式;
(4)重点: 添加在send() 之前
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
window.onload=function(){
var btn=document.getElementById('btn');
btn.onclick=function(){
var username=document.getElementById('username').value;
var pwd=document.getElementById('pwd').value;
// 创建xhr对象
var xhr=null;
if(window.XMLHttpRequest){
xhr=new XMLHttpRequest();
}else{
xhr=new ActiveXObject('Microsoft');
}
var param='name='+username+'&pwd='+pwd;
// post请求数据的的时候 不需要 添加 encodeURI() 转码;
// 在请求数据的时候 不是直接将数据 添加在 url之后 ,而是通过send发送请求
xhr.open('post','06-ajaxPostD