Ajax使用示例(不详细)

来源:互联网 发布:中南邮票交易软件 编辑:程序博客网 时间:2024/06/04 19:41

                     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 = "<font color='red'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + xmlHttp.responseText + "</font>"

                                                                      generateInnerHTML("userIdSpan",xmlHttp.responseText);

                                                               }else {

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

                                                                      generateInnerHTML("userIdSpan","");

                                                               }

                                                        }else {

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

                                                        }

                                                 }

                                   }

                     };

                     xmlHttp.send(null);

原创粉丝点击