var xhr=new XMLHttpRequest();
xhr.open("post","../html/yhgl1.html",true);
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
var inn=document.getElementsByTagName("input").value;
xhr.send('name='+inn);
xhr.onreadystatechange=function(){
if(xhr.readyState==4){
if(xhr.status==200){
var namea=document.getElementById("namea");
var pop=document.getElementById("pop");
var you=document.getElementById("you");
var mim=document.getElementById("mim");
var mam=document.getElementById("mam");
var arr=[namea.value,pop.value,you.value,mim.value,mam.value];
var tr=document.createElement("tr");
var num=document.createElement("td");
num.innerHTML="<input type='checkbox' >";
tr.appendChild(num);
for(var i=0;i<5;i++){
var qwe=document.createElement("td");
qwe.innerHTML=arr[i];
tr.appendChild(qwe);
}
}
}
}
url为html页面,服务器是不支持的,需要的是后台文件的地址。
什么浏览器,本地file测试不要用谷歌浏览器,ajax请求不了本地文件,除非配置过:配置chrome支持本地(file协议)ajax请求
或者发布后通过http协议测试
你请求的是静态页,web服务器一般是不支持静态页post请求的,自己好好检查代码报什么错误,f12看浏览器控制台的提示