Prototype入门_ajax收藏

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>

<script type="text/javascript">
    var xmlRequest = null;
    var READY_STATE_UNLOAD = 0;
    var READY_STATE_LOADING = 1;
    var READY_STATE_LOADED = 2;
    var READY_STATE_INTERACTIVE = 3;
    var READY_STATE_COMPLATE = 4;
           
    function getXMLHttpRequest() {
        if (window.XMLHttpRequest) {
            return new XMLHttpRequest();
        } else {
            return new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
       
    function check() {
            var params = "usr=";
               
             sendRequest("upload2.do", params, "get");
       
            return false;
    }

    function sendRequest(url, params, method) {
                     if (!method){  method="post";  }
         
                        xmlRequest = getXMLHttpRequest();
                    if (xmlRequest) {
                               xmlRequest.onreadystatechange=callBack;
                   
                              xmlRequest.open(method, url, true);
                              xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                             xmlRequest.send(params);
                     }
               
             }
           
             function callBack() {
                         var ready = xmlRequest.readyState;
                         var data = null;
               
                    if (ready == READY_STATE_COMPLATE) {
                                  data = xmlRequest.responseXML;
                   
                                   var flag = data.getElementsByTagName("flag")[0].firstChild.nodeValue;
                   
                               if (flag == "false") {
                                        alert('user or password error,');
                                 } else {
                                          window.open("ok", "_top");
                                    }
                  }                
    }
           
</script>

</head>
<body>
  
   <a href="javascript:check();">kkkkkkkkk</a>
</body>
</html>

你可能感兴趣的:(html,Ajax,Microsoft,prototype)