写出原生ajax的步骤(ajax基本写法)
(1)Get
Var xmlhttp;
if ( window.XMLHttpRequest ) {
Xmlhttp = new XMLHttpRequest;
}else{
Xmlhttp = new ActiveXobject ( “ Microsoft.XMLHTTP ” );
}
Xmlhttp.open ( “ get ” , “ 路径 ” , true );
Xmlhttp.end ( );
Xmlhttp.onreadystatechange = function ( ) {
If ( xmlhttp.readyState == 4 && xmlhttp.Status == 200 ) {
Var res = JSON.parse ( xmlhttp.response )
}
}
(2)post
Var xmlhttp;
if ( window.XMLHttpRequest ) {
Xmlhttp = new XMLHttpRequest;
}else{