ajax新手学习

ajax主要对象就是xmlHttpRequest,其后就是对它的属性进行操作,主要属性有onreadystatechang ,readyState,send,open
<head >
    <title>无标题页</title>
</head>
<body onload ="iajax()"">
        <div id="mydiv">
            <input id="Text1" type="text"  /></div>
        <div id="Div1">
        数据加载中......
        </div>
</body>
</html>
<script language ="javascript" type="text/javascript" >
function iajax()
{
    var xmlObj = null;
    if(window.XMLHttpRequest)
    {
        xmlObj = new XMLHttpRequest();
    }
    else(window.ActiveXObject)
    {
        xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlObj.onreadystatechange = function()
    {
        if(xmlObj.readyState == 4)
        {
      
            document.getElementById ('Div1').innerHTML=xmlObj.responseText;
        }
    }
    xmlObj.open ('GET', "url", true);
    xmlObj.send (null);
}
</script>

你可能感兴趣的:(Ajax)