美文网首页
JS 掏粪工具箱

JS 掏粪工具箱

作者: 禁卫君 | 来源:发表于2020-05-31 22:03 被阅读0次

Ajax 函数

var ajax = function(method, path, data, responseCallback) {
       var r = new XMLHttpRequest()
        // 设置请求方法和请求地址
        r.open(method, path, true)
        //设置发送数据的格式
        r.setRequestHeader('Content-Type', 'application/json')
        // 注册响应函数
        r.onreadystatechange = function() {
              if(r.readyState == 4) {
                  responseCallback(r)
              }
        }
        // 发送请求
        r.send(data)
}

log 函数

var log = function() {
    console.log.apply(console, arguments)
}

appendHtml 函数

var appendHtml = function(element, html) {
    // element 是选中的容器
    element.insertAdjacentHTML('beforeend', html)
}

相关文章

网友评论

      本文标题:JS 掏粪工具箱

      本文链接:https://www.haomeiwen.com/subject/qsorzhtx.html