<script>
let obj = {
name:'Alice',
age:100,
sex:'man',
class:'1905'
}
// 将对象转换成字符串拼接的格式
function objtostring(obj) {
let arr=[];
for(let i in obj){
arr.push(i+'='+obj[i]);
}
return arr.join('&');
}
console.log(objtostring(obj));
let request = new XMLHttpRequest();
request.open('get','http://10.31.158.12/day23/get.php?'+objtostring(obj),true);
request.send();
request.onreadystatechange = function(){
if(request.readyState==4){
if(request.status==200){
}
else {
throw new Error('接口地址有误:'+request.status);
}
}
}
</script>
<?php
// header('content-type:text/html;charset=utf-8');
// error_reporting(0);
echo $_GET["name"];
?>