Bunny's Code Burrow

this is a JS world


  • Home

  • About

  • Archives

  • Tags

  • Search

cookies

Posted on 2020-04-21

cookies

描述cookies localStorage 和sessionStorage的区别

cookie
localStorage
sessionStorage

本身用于浏览器和server通讯
被借用到本地存储来
可用document.cookie =’xxx’来修改
cookie是追加而不是覆盖
可用通过前端对cookie进行赋值,能进行本地存储

cookie 的缺点

  1. 存储大小,最大4kb
  2. http请求时需要发送到服务端,增加请求数据量
  3. 只能用document.cookie=’xxx’来修改
Read more »

ajax tool

Posted on 2020-04-21

ajax tool

jQuery

$(function(){

    //请求参数
    var list ={};
    //
    $.ajax({
    //请求方式
    type:"POST"
    //请求的媒体类型
    contentType:"application/json;charset=UTF-8",
    //请求地址
    url:"http://127.0.0.1/admin/list/"
    //数据,json字符串
    data:JSON.stringify(list)
    //请求成功
    success:function(result){
        console.log(result);
    },
    //请求失败,包含据图的错误信息
    error:function(e){
        console.log(e.status);
        console.log(e.responseText);
    }

    });
});


使用fetch        
fetch('http://example.com/movies.json')
    .then(function(response){
        return response.json();
    })
    .then(function(myJson)){
        console.log(myJson)
    }

ajax interview

Posted on 2020-04-21

ajax interview

手写一个简易的ajax

跨域的常用实现方式

手写一个简易的ajax    
    function ajax(url,successFn){
        const xhr = new XMLHttpRequest()
        xhr.open("GET",url,true)
        xhr.onreadystatechange = function(){
            if(xhr.readyState ===4){
            }
        }
    }
    xhr.send(null)
}
Read more »

CORS

Posted on 2020-04-20

CORS跨域

什么是跨域(同源策略)

JSONP

CORS(服务端支持)

1.同源策略

ajax请求时,浏览器要求当前网页和server必须同源

同源:协议,域名,端口,三者必须一致

加载图片css js 可无视同源策略

  • 可用于统计打点,可使用第三方统计服务
  • jQuery 实现jsonp

    $.ajax({
    url:''
    dataType:'jsonp',
    jsonpCallback:'callback',
    success:function(data){
        console.log(data)
    }
    })
    

ajax

Posted on 2020-04-14

ajax

手写一个简单的ajax

跨域的常用实现方式

知识点

XMLHttpRequest
状态码
跨域:同源策略,跨域解决方案

//get请求
const xhr = new XMLHttpRequest()
xhr.open("GET","/api",false)
xhr.onreadystatechange = function(){
    //这里的函数异步执行,可参考之前JS 基础中的异步模块
    if(xhr.readyState == 4){
        if(xhr.status == 200){
            alert(xhr.responseTexe)
        }
    }
}
xhr.send(null)
Read more »

event delegation

Posted on 2020-04-14

Event delegation

事件代理

<div id="div1">
    <a href="#">a1</a>
    <a href="#">a2</a>
    <a href="#">a3</a>
    <a href="#">a4</a>                
</div>
<button>
    click to add more a
</button>
Read more »

event

Posted on 2020-04-13

Event 事件

编写一个通用的事件监听函数
描述事件冒泡的流程
无限下拉的图片列表,如何监听每个图片的点击

事件绑定

事件冒泡

事件代理

Read more »

BOM

Posted on 2020-04-12

BOM(Browser Object Model)

如何识别浏览器的类型

分析拆解url各个部分

知识点
navigator

//navigator
const ua=navigator.userAgent
const isChrome =ua.indexOf('Chrome');
console.log(isChrome)

screen

screen.width
screen.height

location

console.log(location.href)
console.log(location.protocol)
console.log(location.host)
console.log(location.search)
console.log(location.hash)
console.log(location.pathname)

history

history.back()
history.forward()

access website from AWS to local

Posted on 2020-04-09

How to move website from AWS to local

First, we need the file of pem to connect to the EC2 Instance by SSH.

Then, use PuTTY to connect Windows to EC2.Install PuTTY on your local computer
Download PuTTY first.

Convert private key using PuTTYgen

The private key is a file(.pem file),we need to convert .pem file to a .ppk file with by PuTTY.

Read more »

jswebapi

Posted on 2020-03-17

JS Web API

  • JS基础知识是规定语法(ECMA262标准)
  • JS Web API,网页操作的API(W3C标准)
  • 前者是后者的基础,两者结合才能真正实际应用

JS web API的范围

  • DOM操作
  • BOM操作
  • 事件绑定
  • ajax
  • 存储
Read more »
1…345…16
Jenny Zeng

Jenny Zeng

Loving code ,especially javascript, React Native

155 posts
37 tags
GitHub Linkedin
© 2020 Jenny Zeng
Powered by Hexo
Theme - NexT.Pisces