## 一个完整的ajax的步骤
#### 1.创建ajax核心
#### 2.与服务器建立连接
#### 3.发送请求
#### 4.响应
### 例:一个get请求
~~~
var url = "https://www.easy-mock.com/mock/5bac6df10132334db7167178/testDemo/testDemo";
var xhr = new XMLHttpRequest();
xhr.open('get',url,true);
xhr.send();
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200){ //* status:以数字形式返回http的状态码 readystate值代表服务器响应的变化
var txt = JSON.parse(xhr.responseText); //responseText:获取字符串形式的响应数据
console.log(txt);
}
}
//JSON.parse()方法将json对象解析为JavaScript对象。
//JSON.stringify()将javascript的值,转换为JSON字符串。
~~~
### post请求
#### Post方式要设置一个[请求头](http://www.chengbenchao.top/javascript/780058)
~~~
<div id="test"></div>
<script>
var test = document.getElementById("test");
var xhr = new XMLHttpRequest();
xhr.open("post","https://www.easy-mock.com/mock/5b230e1e6bed703a9b488c69/www.getTest.com/push",true);
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhr.send(null);
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200){
var data = JSON.parse(xhr.responseText);
test.innerHTML = data.data.content
}
}
</script>
~~~
[链接名](链接http)
- 面试题
- 自我介绍
- 问答
- HTML
- 1.@import与link的区别
- CSS
- 1.display: none; 与visibiliy: hidden; 的区别
- 三角形
- margin-top
- 移动端适配问题
- JavaScript
- JavaScript原型和原型链
- 什么是promise
- call、apply、bind区别
- 用函数将字符串转化为驼峰命名
- 数组操作
- 1.筛选
- 2.排序
- 3.反转
- 4.去重
- 字符串方法
- 5.二叉树
- 6.克隆数组
- 重载
- (待完善)JavaScript事件
- dom事件流
- 四则运算符
- cookie,LocalStorage,sessionStorage
- 浅拷贝和深拷贝
- 对象
- 浏览器
- web性能优化
- 定时器
- 回调地狱
- 遍历的几种方式
- this指向
- HTTP
- 输入ur发生了什么
- ajax
- 跨域
- jquery跨域
- axios
- vue
- (待完善)缓存
- bootstarp
- es6
- 01解构赋值
- (未完成)class