Ajax代码样本

var xmlHttp;


function ajaxfunction(i){
    if(window.ActiveXObject){//usually for old IE
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
        if(window.XMLHttpRequest){//for new IE and other browers, such as Chrome
    xmlHttp=new XMLHttpRequest();
    }
    xmlHttp.onreadystatechange=readyStateChangHandle;
    url="page.php";//;the page applying Ajax
    url+="?page="+i+"&sid"+Math.random();
    xmlHttp.open("GET",url,true);
     xmlHttp.send();
}
function readyStateChangHandle(){
    if(xmlHttp.readyState===4&&xmlHttp.status===200){
        xmlDoc=xmlHttp.responseText;
        var s3=document.getElementById("s3");
        s3.innerHTML= xmlDoc;
    }
}
ajaxfunction(1);

猜你喜欢

转载自blog.csdn.net/sinat_30658665/article/details/80722580