ajax

原生ajax

    if (window.XMLHttpRequest) {
        xmlhttp=new XMLHttpRequest();
    } else {
        // code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.open("GET","record.json",true);
    xmlhttp.send();

    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4 && xmlhttp.status==0) {
        // document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
        var ans = xmlhttp.responseText;
        console.log(ans);

        }
      }

其中如果status=0时可能是因为没有装网站所需的服务器,比如IIS或者Apache之类软件。

因为status=0是本地成功响应的代码。

原文地址:https://www.cnblogs.com/hemi/p/4306179.html