5.XMLHttpRequest(传参)
<h3>XMLHttpRequest</h3>
<p id="result"></p>
<script>
var xhr.new XMLHttpRequest;
xhr.open('post','8-5.php');
//xhr.open('get','8-5.php?name=itcast&age=10&sex=男');
xhr.setRequestHeader('Content-Type','applicaiont/x-www-form-urlencoded');
xhr.send('name=itcat&age=10&sex=男');
//xhr.send(null);
xhr.onreadystatechange=function(){
if(xhr.readyState==4&&xhr.status==200){
var result=xhr.responseText;
console.log(result);
}
}
</script>
<?php
print_r($_POST);
//print_r($_GET);
?>
6.XMLHttpRequest(API)
<h3>XMLHttpRequest</h3>
<p id="result"></p>
<script>
var xhr.new XMLHttpRequest;
xhr.open('post','8-5.php');
xhr.setRequestHeader('Content-Type','applicaiont/x-www-form-urlencoded');
xhr.send('name=itcat&age=10&sex=男');
xhr.onreadystatechange=function(){
//console.log(xhr.statusText);
//console.log(xhr.getAllResponseHeaders());
console.log(xhr.getResponseHeader('sever'));
if(xhr.readyState==4&&xhr.status==200){
var result=xhr.responseText;
console.log(result);
}
}
</script>