1.Ajax的运行环境
Ajax技术需要运行在网站环境种才能生效,当前课程会使用Node创建服务器作为网站服务器
2.Ajax的实现步骤
- 创建ajax对象
var xhr = new XMLHttpRequest()
- 请求方式和地址
xhr.open('get','http://192.168.0.103/get')
- 发送请求
xhr.send()
- 获取服务器端响应到客户端的数据
xhr.onload = function(){
console.log(xhr.responseText);
}
- 整合
<script>
//1.创建ajax对象
var xhr = new XMLHttpRequest()
// 2.请求方式和地址
xhr.open('get','http://192.168.0.103/get')
// 3.发送请求
xhr.send()
// 4.获取服务器端响应到客户端的数据
xhr.onload = function(){
console.log(xhr.responseText);
}
</script>