(1)手写promise封装ajax请求
<script type="text/javascript">
var ajaxOptions = {
url: 'url',
method: 'GET',
async: true,
data: null,
dataType: 'text',
}
function ajax(protoOptions) {
var options = {
};
for (var i in ajaxOptions) {
options[i] = protoOptions[i] || ajaxOptions[i];
}
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open(options.method, options.url, options.async);
xhr.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
resolve(this.responseText, this);
} else {
var resJson = {
code: this.status,
response: this.response
}
reject(resJson, this)
}
}
xhr.send()
})
}
</script>[添加链接描述](https://www.jianshu.com/p/7f1411317295)
(2)在地址栏输入网址敲回车发生了什么?
文章描述
(3)什么是BFC?什么情况下触发BFC
- html根元素
- float 不为 none
- 绝对定位元素 也就是 position 为 absolute 和 fixed
- 行内快元素 display 为 inline-block
- display 为 table-cell inline-block flex inline-flex grid inline-grid table-caption(表格标题)
- overflow 不为 visible
BFC