响应PHP传过来的json,把数组解析 并且传送到HTML
<script>inquiry.onclick=function(){vardpt=inquiry.value;if(dpt==="0"){return;}varxhr=...
<script>
inquiry.onclick=function(){
var dpt=inquiry.value;
if(dpt==="0"){
return;
}
var xhr=new XMLHttpRequest();
xhr.onreadystatechange=function(){
if(xhr.readyState===4){
if(xhr.status===200){
doResponse(xhr);
}else{
alert('响应完成但是有问题');
}
}
}
/*[{"eid":"1","ename":"\u798f\u6797","pic":"C:\/HTML\/img\/section\/album-01.jpeg","salary":"8000","deptID":"1"},{"eid":"2","ename":"\u5218\u946b","pic":"C:\/HTML\/img\/section\/album-02.jpeg","salary":"8500","deptID":"1"}]**PHP传过来的数据*/
xhr.open('POST','emp_select.php',true);
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xhr.send(`deptID=${dpt}`);
function doResponse(xhr){
console.log('开始处理响应数据');
console.log(xhr);
var result = JSON.parse(xhr.responseText);
console.log(result);
/*这怎么填*/
var tbody=document.querySelector('#tableProduct tbody');
tbody.innerHTML +=html;
}
}
</script> 展开
inquiry.onclick=function(){
var dpt=inquiry.value;
if(dpt==="0"){
return;
}
var xhr=new XMLHttpRequest();
xhr.onreadystatechange=function(){
if(xhr.readyState===4){
if(xhr.status===200){
doResponse(xhr);
}else{
alert('响应完成但是有问题');
}
}
}
/*[{"eid":"1","ename":"\u798f\u6797","pic":"C:\/HTML\/img\/section\/album-01.jpeg","salary":"8000","deptID":"1"},{"eid":"2","ename":"\u5218\u946b","pic":"C:\/HTML\/img\/section\/album-02.jpeg","salary":"8500","deptID":"1"}]**PHP传过来的数据*/
xhr.open('POST','emp_select.php',true);
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xhr.send(`deptID=${dpt}`);
function doResponse(xhr){
console.log('开始处理响应数据');
console.log(xhr);
var result = JSON.parse(xhr.responseText);
console.log(result);
/*这怎么填*/
var tbody=document.querySelector('#tableProduct tbody');
tbody.innerHTML +=html;
}
}
</script> 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询