* [1.http請求](http://www.hmoore.net/chengbenchao/javascript/780058#1http_1)
* [2.請求響應](http://www.hmoore.net/chengbenchao/javascript/780058#2_8)
* [3.一個完整的ajax的步驟](http://www.hmoore.net/chengbenchao/javascript/780058#3ajax_13)
* [1.創建](http://www.hmoore.net/chengbenchao/javascript/780058#1ajax_14)[ajax核心](http://www.hmoore.net/chengbenchao/javascript/780058)對象
* [2.與服務器建立](http://www.hmoore.net/chengbenchao/javascript/780058#2_15)[連接](http://www.hmoore.net/chengbenchao/javascript/780058)
* [3.發送](http://www.hmoore.net/chengbenchao/javascript/780058#3_16)[請求](http://www.hmoore.net/chengbenchao/javascript/780058)
* [4.響應](http://www.hmoore.net/chengbenchao/javascript/780058#4_17)
* [get請求](http://www.hmoore.net/chengbenchao/javascript/780058#get_18)
* [post請求](http://www.hmoore.net/chengbenchao/javascript/780058#post_38)
* [Post方式要設置一個](http://www.hmoore.net/chengbenchao/javascript/780058#Post_39)[請求頭](http://www.hmoore.net/chengbenchao/javascript/780058)
## 1.http請求
> 定義:http計算機通過網絡進行通信的規則
> 
> 
> 
> 
> 
## 2.請求響應
* open(method,url,asyn)
asyn值默認為true
* send()
* onreadystatechange
## 3.一個完整的ajax的步驟
#### 1.創建[ajax核心](http://www.hmoore.net/chengbenchao/javascript/780058)對象
#### 2.與服務器建立[連接](http://www.hmoore.net/chengbenchao/javascript/780058)
#### 3.發送[請求](http://www.hmoore.net/chengbenchao/javascript/780058)
#### 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){
var txt = JSON.parse(xhr.responseText);
console.log(txt);
}
}
~~~
JSON.parse()方法將json對象解析為JavaScript對象。
JSON.stringify()將javascript的值,轉換為JSON字符串。
* responseText:獲取字符串形式的響應數據
* status:以數字形式返回http的狀態碼
* readystate值代表服務器響應的變化

### post請求
#### Post方式要設置一個[請求頭](http://www.hmoore.net/chengbenchao/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>
~~~
- 第一章.git
- 1-1 git基本命令
- 1-2 ssh的配置
- 1-3 版本回退
- 第二章 markdown基本語法
- 第三章 HTML
- 3-1 HTML標簽概念
- 3-2 html結構
- 3-3 基本標簽
- 3-4 input輸入框
- 3-5 table表格
- 第四章 CSS
- 4-1 CSS基礎
- 4-2 基本樣式
- 4-3 選擇器
- 4-4 盒子模型
- 4-5 進階樣式
- 4-6 樣式繼承
- 4-7 浮動
- 4-8 定位
- 4-8 水平垂直居中
- 4-9 特殊情況
- 4-10 表單
- 4-11 2D效果
- 4-12 BFC
- 第五章 JavaScript筆記
- 5-1JS基礎
- 5-2 DOM介紹
- 5-3 DOM操作詳解
- 5-4 JSON詳解
- 第六章 jQuery
- 6-1 jQuery概述
- 6-2 jQuery選擇器
- 6-3 jQuery常用操作
- 第七章 AJAX
- 7-1 原生ajax
- 7-2 http,get,post
- 7-3 跨域
- 7-4 jQuery-ajax
- Web前端命名規范