var xhr = new XHLHttpRequest();
xhr.open();
xhr.send();
console.log(1);
var data = http://www.mamicode.com/null;
xhr.onreadystatechange = function(){
console.log(2);
data = xhr.responseText;
}
console.log(data); // data先输出才执行函数,所以应使用回调函数实现
console.log(3);
<style>td.linenos { background-color: #f0f0f0; padding-right: 10px }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px }
pre { line-height: 125% }
body .hll { background-color: #ffffcc }
body { background: #f8f8f8 }
body .c { color: #408080; font-style: italic }
body .err { border: 1px solid #FF0000 }
body .k { color: #008000; font-weight: bold }
body .o { color: #666666 }
body .cm { color: #408080; font-style: italic }
body .cp { color: #BC7A00 }
body .c1 { color: #408080; font-style: italic }
body .cs { color: #408080; font-style: italic }
body .gd { color: #A00000 }
body .ge { font-style: italic }
body .gr { color: #FF0000 }
body .gh { color: #000080; font-weight: bold }
body .gi { color: #00A000 }
body .go { color: #888888 }
body .gp { color: #000080; font-weight: bold }
body .gs { font-weight: bold }
body .gu { color: #800080; font-weight: bold }
body .gt { color: #0044DD }
body .kc { color: #008000; font-weight: bold }
body .kd { color: #008000; font-weight: bold }
body .kn { color: #008000; font-weight: bold }
body .kp { color: #008000 }
body .kr { color: #008000; font-weight: bold }
body .kt { color: #B00040 }
body .m { color: #666666 }
body .s { color: #BA2121 }
body .na { color: #7D9029 }
body .nb { color: #008000 }
body .nc { color: #0000FF; font-weight: bold }
body .no { color: #880000 }
body .nd { color: #AA22FF }
body .ni { color: #999999; font-weight: bold }
body .ne { color: #D2413A; font-weight: bold }
body .nf { color: #0000FF }
body .nl { color: #A0A000 }
body .nn { color: #0000FF; font-weight: bold }
body .nt { color: #008000; font-weight: bold }
body .nv { color: #19177C }
body .ow { color: #AA22FF; font-weight: bold }
body .w { color: #bbbbbb }
body .mf { color: #666666 }
body .mh { color: #666666 }
body .mi { color: #666666 }
body .mo { color: #666666 }
body .sb { color: #BA2121 }
body .sc { color: #BA2121 }
body .sd { color: #BA2121; font-style: italic }
body .s2 { color: #BA2121 }
body .se { color: #BB6622; font-weight: bold }
body .sh { color: #BA2121 }
body .si { color: #BB6688; font-weight: bold }
body .sx { color: #008000 }
body .sr { color: #BB6688 }
body .s1 { color: #BA2121 }
body .ss { color: #19177C }
body .bp { color: #008000 }
body .vc { color: #19177C }
body .vg { color: #19177C }
body .vi { color: #19177C }
body .il { color: #666666 }</style>