对初学AJAX的同学会有协助的。
----------ajax.js---------------varrequest=false;try{ request=newXMLHttpRequest();}catch(trymicrosoft){ try{ request=newActiveXObject("Msxml2.XMLHTTP"); } catch(othermicrosoft){ try{ request=newActiveXObject("Microsoft.XMLHTTP"); } catch(failed){ request=false; } }}if(!request)alert("ErrorinitializingXMLHttpRequest!");functiongetCustomerInfo(){ document.getElementById("output").innerHTML="Loading..."; document.getElementById("submit").disabled=true; varname=document.getElementById("name").value; vartext=document.getElementById("text").value; varkey=document.getElementById("key").value; varanswer=document.getElementById("answer").value; varpoststr="name="+name+"&text="+text+"&key="+key+"&answer="+answer; varurl="doit.php"; request.open("POST",url,true); request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); request.send(poststr); request.onreadystatechange=updatePage;}functionupdatePage(){if(request.readyState==4)if(request.status==200)document.getElementById("output").innerHTML=request.responseText;elseif(request.status==404)alert("目标地址不存在");elsealert("警告:错误代码"+request.status);}functiongetInfo(){ document.getElementById("output1").innerHTML="Loading..."; varurl="show.php"; vard=newDate().getTime(); request.open("GET",url+"?d="+d.toString(),true); request.onreadystatechange=updatePage1; request.send();}functionupdatePage1(){if(request.readyState==4)if(request.status==200)document.getElementById("output1").innerHTML=request.responseText;elseif(request.status==404)alert("目标地址不存在");elsealert("警告:错误代码"+request.status);}
2017/4/14 22:50:25
79KB
ajax
1