日期:2014-05-17  浏览次数:20736 次

请各位高手帮忙看一下 我用Ajax向servlet发送请求 在servlet中接收不到参数都是为空的 这是哪里出问题了 谢谢
jsp中的代码:
<script type="text/javascript">
 var request = null;
        function createRequest() {
            if (request != null) return;
            if (window.ActiveXObject) {
                request = new ActiveXObject("Microsoft.XMLHTTP");
            } else if (window.XMLHttpRequest) {
                request = new XMLHttpRequest();
            }
            if (request.overrideMimeType) {
                request.overrideMimeType("text/xml");
            }
        }
        function login() {
            var userName = document.getElementById("userName").value;
            var password = document.getElementById("password").value;
            alert(userName + "   " + password);
            createRequest();
            alert("创建对象完成"+request);
            var url = "./servlet/Myservlet? userName="+userName+"& password="+password;
            url=encodeURI(url);
            alert("url的值"+url);
            
            request.open("POST",url,true);
            request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            alert("open对象完成");
            request.onreadystatechange=result;
            alert("回调完成");
            request.send(null);
            alert("消息 发送完成");
        }
        function result(){
          if(request.readyState==4){
            if(request.status==200){
              document.getElementById("loginState").innerHTML=request.responseText;
            }
     &nb