<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript">
function f1() {
var xhr = new XMLHttpRequest();
xhr.open('get','./03.php')
xhr.send(null)
xhr.onreadystatechange = function () {
if (xhr.readyState==4){
console.log(xhr.responseText);
document.getElementById('result').innerHTML = xhr.responseText;
}
}
}
</script>
</head>
<body>
<h2> ajax 接收到服务器返回的信息</h2>
<input type="button" value="触发" onclick="f1()" />
<div id="result" > </div>
</body>
</html>
<?php
/**
* Created by PhpStorm.
* User: bochaoceng
* Date: 12/29/17
* Time: 13:50
*/
echo "<div>Today is very <span style='color: red'> good </span> </div>";