ajax无刷新技术(异步通讯技术)

new XMLHTTPRequest

//ajax

function new_ajax(url,success,fail)
{//1.创建ajax对象    
    if(window.XMLHttpRequest){//兼容非IE6P        
        var oAjax=new XMLHttpRequest();    
    }else{//IE6        
        var oAjax=new ActiveXObject("Microsoft.XMLHTTP");   
    }    
    //2.链接服务器    
    //open(方法,文件名,异步传输)   
    oAjax.open('GET',url,true);    
    //3.发送请求    
    oAjax.send();    
    //4.接收返回值    
    oAjax.onreadystatechange=function(){//oAjax.readyState浏览器和服务器交互到哪一步        //0未初始化,还没有调用open()        //1载入,已调用send()方法,正在发送请求        //2载入完成        //3解析        //4完成,成败都会        if(oAjax.readyState==4)//读取完成        {            if(oAjax.status==200)//成功            {               
        success(oAjax.responseText);            
    }else{               
        fail(oAjax.status);            
    }        
    }    
    };
}