1.兼容写法
<script>
//用没有定义的变量-保存
//用没有定义的属性-undifind
window.onload = function(){
var oBtn = document.getElementById('btn1');
oBtn.onclick = function(){
//兼容IE6
var oAjax = window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
oAjax.open('GET','https://cdn.bootcss.com/jquery/3.2.1/core.js',true);
oAjax.send();
oAjax.onreadystatechange = function()
{
if(oAjax.readyState == 4)//通讯完成
{
if(oAjax.status==200)//通讯成功
{
alert(oAjax.responseText);
}
else
{
alert('fail');
}
}
}
}
}
</script>