0
 function getXmlHttpRequestObject()
            {
                var xmlHttp = false;
                if (window.XMLHttpRequest)
                {
                    return new XMLHttpRequest(); //To support the browsers IE7+, Firefox, Chrome, Opera, Safari
                }
                else if(window.ActiveXObject)
                {
                    return new ActiveXObject("Microsoft.XMLHTTP"); // For the browsers IE6, IE5 
                }
                else
                {
                    alert("Error due to old verion of browser upgrade your browser");
                }
            }

            var xmlhttp = new getXmlHttpRequestObject(); //xmlhttp holds the ajax object

            function servletPost() {
                if(xmlhttp) { 
                   var txt = document.getElementById("txtname");
                    var txtname=document.URL;
                    xmlhttp.open("POST","ServletPost",true);
                    xmlhttp.onreadystatechange = handleServletPost;
                    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                    xmlhttp.send("txtname=" + txtname); 

                }
            }

            function handleServletPost() {
                if (xmlhttp.readyState == 4) {
                    if(xmlhttp.status == 200) {
                        document.getElementById("message").innerHTML=xmlhttp.responseText; 
                    }
                    else {
                        alert("Ajax calling error");
                    }
                }
            }

これは私のコードです関数servletPost()はデータをサーブレットに送信していますが、txtnameのみがサーブレットに送られ、他の値はサーブレットに送られませんどうすれば解決できますか助けてください

4

2 に答える 2

0

あなたのコードでは、パラメーター txtname を 1 つだけ送信していることがわかります。

さらにパラメータを送信する場合は、間に「&」を追加します。

params = "txtname=" + txtname + "&txt=" + txt;
于 2013-04-11T07:27:50.757 に答える