zoukankan      html  css  js  c++  java
  • ajax基础

    function ajax(url, fn) {
           //创建对象
           // IE早期版本是new ActiveXObject() 高级版本已不支持
            var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {// 状态发生变化时,函数被回调
                // 监听readystate
               if (xhr.readyState === 4) {
                    
                    if (xhr.status === 200) {
                        // 成功,通过responseText拿到响应的文本:
                         console.log(xhr.responseText);
                    } else {
                        // 失败,根据响应码判断失败原因:
                        console.log(xhr.status);
                    }
               }else {
                    // HTTP请求还在继续...
                }
            }
           //打开链接
    xhr.open('GET', url, true);
    //发送请求
    xhr.send(null);
    }

    ajax基于XMLHttpRequest

    关键方法:

    XMLHttpRequest
    open
    send
    readystatechange

    关键属性:

    readyState
    status
    responseText(还有responseXML )
  • 相关阅读:
    Jquery入门
    微服务
    数组
    流程控制
    GO的整型
    Go的巧记
    变量和常量
    Golang
    股票入市指南
    linux 命令行操作
  • 原文地址:https://www.cnblogs.com/zyjzz/p/7236458.html
Copyright © 2011-2022 走看看