1 再次复习ajax 2 3 ajax库 4 ajax(url,fnsucc,fnFaild) 5 6 7 function ajax(url, fnSucc, fnFaild) 8 { 9 //1.创建Ajax对象 10 var oAjax=null; 11 12 if(window.XMLHttpRequest)//ajax对象的两种获取方法 13 { 14 oAjax=new XMLHttpRequest(); 15 } 16 else 17 { 18 oAjax=new ActiveXObject("Microsoft.XMLHTTP"); 19 } 20 21 //2.连接服务器 22 oAjax.open(‘GET‘, url, true); 23 24 //3.发送请求 25 oAjax.send(); 26 27 //4.接收服务器的返回 28 oAjax.onreadystatechange=function () 29 { 30 if(oAjax.readyState==4) //完成 31 { 32 if(oAjax.status==200) //成功 33 { 34 fnSucc(oAjax.responseText); 35 } 36 else 37 { 38 if(fnFaild) 39 fnFaild(oAjax.status); 40 } 41 } 42 }; 43 }
原文:http://www.cnblogs.com/windSamW/p/4951475.html