Ajax使用示例(不详细)

                     var xmlHttp;

                     if(window.XMLHttpRequest){             //不是ie

                                   xmlHttp = new XMLHttpRequest();

                     }else if(window.ActiveXObject){         //ie

                                   xmlHttp =new ActiveXObject("Microsoft.XMLTHHP");

                     }

 

                     var url = "user_validate.jsp?userId=" + trim(field.value) + "&time=" + new Date().getTime();

                     xmlHttp.open("GET",url,true);

                     xmlHttp.onreadystatechange = function(){

                                   //alert(xmlHttp.readyState);

                                   if(xmlHttp.readyState ==4){

                                          if (xmlHttp.readyState == 4) {

                                                        //HTTP协议状态为成功

                                                        if (xmlHttp.status == 200) {

                                                               if (trim(xmlHttp.responseText) != "") {

                                                                      //alert(xmlHttp.responseText);

                                                                      //document.getElementById("userIdSpan").innerHTML = "            " + xmlHttp.responseText + ""

                                                                      generateInnerHTML("userIdSpan",xmlHttp.responseText);

                                                               }else {

                                                                      //document.getElementById("userIdSpan").innerHTML = "";

                                                                      generateInnerHTML("userIdSpan","");

                                                               }

                                                        }else {

                                                               alert("请求失败,错误码=" + xmlHttp.status);

                                                        }

                                                 }

                                   }

                     };

                     xmlHttp.send(null);

你可能感兴趣的:(ajax,xmlhttprequest,function,url,date,null)